Reviewed-on: https://git.openi.org.cn/OpenI/aiforge/pulls/803 Reviewed-by: lewis <747342561@qq.com>tags/v1.21.12.1
| @@ -14,6 +14,8 @@ var customMigrations = []CustomMigration{ | |||||
| {"Custom v1 Topic struct change to support chinese", syncTopicStruct}, | {"Custom v1 Topic struct change to support chinese", syncTopicStruct}, | ||||
| } | } | ||||
| var customMigrationsStatic = []CustomMigration{} | |||||
| func MigrateCustom(x *xorm.Engine) { | func MigrateCustom(x *xorm.Engine) { | ||||
| for _, m := range customMigrations { | for _, m := range customMigrations { | ||||
| @@ -27,6 +29,17 @@ func MigrateCustom(x *xorm.Engine) { | |||||
| } | } | ||||
| func MigrateCustomStatic(x *xorm.Engine) { | |||||
| for _, m := range customMigrationsStatic { | |||||
| log.Info("Migration: %s", m.Description) | |||||
| if err := m.Migrate(x); err != nil { | |||||
| log.Error("Migration: %v", err) | |||||
| } | |||||
| } | |||||
| } | |||||
| func syncTopicStruct(x *xorm.Engine) error { | func syncTopicStruct(x *xorm.Engine) error { | ||||
| query := "ALTER TABLE topic ALTER COLUMN name TYPE varchar(105);" | query := "ALTER TABLE topic ALTER COLUMN name TYPE varchar(105);" | ||||
| @@ -190,7 +190,7 @@ func setEngine(engine *xorm.Engine, table []interface{}, database *setting.DBInf | |||||
| engine.SetMaxIdleConns(setting.Database.MaxIdleConns) | engine.SetMaxIdleConns(setting.Database.MaxIdleConns) | ||||
| engine.SetConnMaxLifetime(setting.Database.ConnMaxLifetime) | engine.SetConnMaxLifetime(setting.Database.ConnMaxLifetime) | ||||
| engine.Sync2(table...) | engine.Sync2(table...) | ||||
| MigrateCustom(engine) | |||||
| return nil | return nil | ||||
| } | } | ||||
| @@ -202,6 +202,7 @@ func SetEngine() (err error) { | |||||
| if err = setEngine(x, tables, setting.Database); err != nil { | if err = setEngine(x, tables, setting.Database); err != nil { | ||||
| return err | return err | ||||
| } | } | ||||
| MigrateCustom(x) | |||||
| xStatistic, err = getEngine(setting.DatabaseStatistic) | xStatistic, err = getEngine(setting.DatabaseStatistic) | ||||
| if err != nil { | if err != nil { | ||||
| @@ -210,7 +211,7 @@ func SetEngine() (err error) { | |||||
| if err = setEngine(xStatistic, tablesStatistic, setting.DatabaseStatistic); err != nil { | if err = setEngine(xStatistic, tablesStatistic, setting.DatabaseStatistic); err != nil { | ||||
| return err | return err | ||||
| } | } | ||||
| MigrateCustomStatic(xStatistic) | |||||
| return nil | return nil | ||||
| } | } | ||||