[优化] 重构数据库迁移逻辑,添加版本管理和验证功能

This commit is contained in:
ryan
2026-05-31 14:32:43 +08:00
parent 4ae6c2718f
commit f365b3d331
16 changed files with 421 additions and 864 deletions
+27
View File
@@ -0,0 +1,27 @@
package migrate
import "gorm.io/gorm"
func init() {
Register(V13())
}
func V13() Migration {
return Migration{
FromVersion: 12,
ToVersion: 13,
Migrate: migrateV13,
Validate: validateV13,
}
}
func migrateV13(ctx Context, db *gorm.DB, backend string) error {
if err := ctx.ApplyCurrentSchema(db, backend); err != nil {
return err
}
return ctx.EnsureDefaultWAFRuleGroup(db)
}
func validateV13(ctx Context, db *gorm.DB, backend string) error {
return ctx.ValidateDatabaseSchemaVersion(db, backend, 13)
}