优化结构

This commit is contained in:
Yvan
2026-08-21 00:01:48 +08:00
parent e65cf0b1d0
commit 746e33e027
344 changed files with 1021 additions and 578 deletions
+20
View File
@@ -0,0 +1,20 @@
package migration
import "gorm.io/gorm"
// CreateMissingTables creates only schemas that are absent. Existing tables
// are intentionally left untouched: GORM's MySQL column diff path can panic
// when older servers return incomplete information_schema metadata, and this
// project does not support implicit legacy-schema upgrades through AutoMigrate.
func CreateMissingTables(db *gorm.DB, models ...any) error {
missing := make([]any, 0, len(models))
for _, model := range models {
if model != nil && !db.Migrator().HasTable(model) {
missing = append(missing, model)
}
}
if len(missing) == 0 {
return nil
}
return db.Migrator().CreateTable(missing...)
}