fix: preserve legacy time casts throughout index migrations
This commit is contained in:
@@ -74,7 +74,17 @@ func migrateQueryIndexes(db *gorm.DB, indexes []businessQueryIndex) error {
|
||||
}
|
||||
// 同一大表的多个索引合并构建,减少重复扫描。
|
||||
if len(additions) > 0 {
|
||||
if err := db.Exec("ALTER TABLE `" + table + "` " + strings.Join(additions, ",") + ", ALGORITHM=INPLACE, LOCK=NONE").Error; err != nil {
|
||||
build := func(conn *gorm.DB) error {
|
||||
return conn.Exec("ALTER TABLE `" + table + "` " + strings.Join(additions, ",") + ", ALGORITHM=INPLACE, LOCK=NONE").Error
|
||||
}
|
||||
// Later indexes also evaluate the historical generated time column.
|
||||
// Apply the same connection-local compatibility rule as its first index.
|
||||
if table == "tab_user" && db.Migrator().HasColumn(table, "sw_register_time_unix") {
|
||||
err = withLegacyRegistrationCast(db, build)
|
||||
} else {
|
||||
err = build(db)
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("add query indexes on %s: %w", table, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user