19 lines
740 B
Go
19 lines
740 B
Go
package business
|
|
|
|
import "gorm.io/gorm"
|
|
|
|
// 区服汇总按创角时间读取原始记录;旧表只有 play_time 索引,导致每日创角扫描全表。
|
|
func migrateServerReportIndex(db *gorm.DB) error {
|
|
if db.Dialector.Name() != "mysql" || !db.Migrator().HasTable("tab_user_play_info") {
|
|
return nil
|
|
}
|
|
var existing int64
|
|
if err := db.Raw("SELECT COUNT(*) FROM information_schema.statistics WHERE table_schema=DATABASE() AND table_name='tab_user_play_info' AND column_name='create_time' AND seq_in_index=1").Scan(&existing).Error; err != nil {
|
|
return err
|
|
}
|
|
if existing > 0 {
|
|
return nil
|
|
}
|
|
return db.Exec("ALTER TABLE tab_user_play_info ADD INDEX idx_sw_play_create_time(create_time), ALGORITHM=INPLACE, LOCK=NONE").Error
|
|
}
|