fix: validate explicit migrations and preserve large business ids
This commit is contained in:
+21
-1
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user