feat: 迁移预警规则管理和历史分类查询
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
func Migrations() []migration.Step {
|
||||
return []migration.Step{{ID: "202611030005_business_password_reset", Migrate: func(db *gorm.DB) error {
|
||||
return []migration.Step{{ID: "202611030006_business_alert_schema", Migrate: migrateAlertSchema}, {ID: "202611030005_business_password_reset", Migrate: func(db *gorm.DB) error {
|
||||
return migration.CreateMissingTables(db, &resetCodePO{}, &resetTokenPO{})
|
||||
}}, {ID: "202611030004_business_binding_locks", Migrate: func(db *gorm.DB) error {
|
||||
return migration.CreateMissingTables(db, &bindingLockPO{})
|
||||
@@ -35,3 +35,27 @@ func Migrations() []migration.Step {
|
||||
})
|
||||
}}}
|
||||
}
|
||||
|
||||
func migrateAlertSchema(db *gorm.DB) error {
|
||||
if err := migration.CreateMissingTables(db, &alertRulePO{}, &alertRecordPO{}, &alertLogPO{}); err != nil {
|
||||
return err
|
||||
}
|
||||
if db.Dialector.Name() != "mysql" {
|
||||
return nil
|
||||
}
|
||||
columns, err := db.Migrator().ColumnTypes(&alertRulePO{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, column := range columns {
|
||||
if column.Name() == "mom_threshold" {
|
||||
precision, scale, ok := column.DecimalSize()
|
||||
if ok && precision >= 7 && scale >= 2 {
|
||||
return nil
|
||||
}
|
||||
// 原页面允许 9999%,旧 decimal(5,2) 装不下;扩大精度且不改变已有值。
|
||||
return db.Migrator().AlterColumn(&alertRulePO{}, "MomThreshold")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user