package version import ( "IotAdmin/migration/models/iot" "runtime" "gorm.io/gorm" "IotAdmin/migration" "IotAdmin/migration/models" ) func init() { _, fileName, _, _ := runtime.Caller(0) migration.Migrate.SetVersion(migration.GetFilename(fileName), _1711599710047Test) } func _1711599710047Test(db *gorm.DB, version string) error { return db.Transaction(func(tx *gorm.DB) error { // 新增表结构 使用过程中请删除此段代码 err := tx.Debug().Migrator().AutoMigrate( new(iot.Group), new(iot.Device), new(iot.MeterCalc), ) if err != nil { return err } return tx.Create(&models.Migration{ Version: version, }).Error }) }