refactor(stats): slim final daily mileage table

This commit is contained in:
lingniu
2026-07-08 16:58:25 +08:00
parent da669fae94
commit 536b0bfee6
7 changed files with 109 additions and 135 deletions

View File

@@ -72,7 +72,7 @@ func (w *Writer) EnsureSchema(ctx context.Context) error {
}
}
for _, statement := range DailyMileageAlterSQL {
if _, err := w.exec.ExecContext(ctx, statement); err != nil && !isDuplicateColumnError(err) {
if _, err := w.exec.ExecContext(ctx, statement); err != nil && !isIgnorableSchemaChangeError(err) {
return err
}
}
@@ -284,12 +284,17 @@ func sourceKey(env envelope.FrameEnvelope) string {
return SourceKey(env.Protocol, env.Phone, env.DeviceID, NormalizeSourceIP(env.SourceEndpoint))
}
func isDuplicateColumnError(err error) bool {
func isIgnorableSchemaChangeError(err error) bool {
if err == nil {
return false
}
text := strings.ToLower(err.Error())
return strings.Contains(text, "duplicate column") || strings.Contains(text, "1060")
return strings.Contains(text, "duplicate column") ||
strings.Contains(text, "1060") ||
strings.Contains(text, "duplicate key name") ||
strings.Contains(text, "1061") ||
strings.Contains(text, "can't drop") ||
strings.Contains(text, "1091")
}
type mileageFieldMapping struct {