优化结构
This commit is contained in:
@@ -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...)
|
||||
}
|
||||
Reference in New Issue
Block a user