fix: validate explicit migrations and preserve large business ids

This commit is contained in:
Yvan
2026-11-06 07:00:05 +08:00
parent f6f2a4745e
commit 0f0ec2e6d7
53 changed files with 2653 additions and 1445 deletions
+21 -1
View File
@@ -9,7 +9,9 @@ import (
"strings"
"kra/internal/config"
"kra/internal/data"
"kra/internal/logging"
"kra/internal/modules"
"kra/internal/server/router"
"kra/internal/service/dto"
systemservice "kra/internal/service/system"
@@ -32,7 +34,9 @@ var (
// Version is the version of the compiled software.
Version string
// flagconf is the config flag.
flagconf string
flagconf string
flagMigrate bool
flagCheckSchema bool
id, _ = os.Hostname()
)
@@ -47,6 +51,8 @@ const (
func init() {
flag.StringVar(&flagconf, "conf", "./configs", "config path, eg: -conf config.yaml")
flag.BoolVar(&flagMigrate, "migrate", false, "apply and verify all migrations, then exit without starting the service")
flag.BoolVar(&flagCheckSchema, "check-schema", false, "verify migration versions and required schema without writing, then exit")
}
// taskRegistry builds the process-wide registry from the dependency-free task
@@ -159,6 +165,20 @@ func main() {
loggerControl.Reload(root, options)
})
defer unsubscribeLogger()
if flagMigrate || flagCheckSchema {
if flagMigrate && flagCheckSchema {
panic("-migrate and -check-schema are mutually exclusive")
}
var database *config.Database
if bc.Data != nil {
database = bc.Data.Database
}
if err := data.MigrateDatabase(context.Background(), database, modules.Catalog(), logger, flagCheckSchema); err != nil {
panic(err)
}
logger.Info("database migration verification completed", "mod", "system", "check_only", flagCheckSchema)
return
}
application, cleanup, err := wireApp(bc.Server, runtime, logger, loggerControl, Version)
if err != nil {