-
Notifications
You must be signed in to change notification settings - Fork 104
Open
Description
My database is clean, without any tables.
I want to InitSchema and do some other migrations, just like this:
m := gormigrate.New(db, gormigrate.DefaultOptions, []*gormigrate.Migration{
&gormigrate.Migration{
ID: "20230716",
Migrate: func(tx *gorm.DB) error {
return tx.Exec("INSERT INTO user (username) VALUES ('admin')").Error
},
Rollback: func(tx *gorm.DB) error {
return tx.Exec("DELETE FROM user WHERE username='admin'").Error
},
},
})
m.InitSchema(func(tx *gorm.DB) error {
err := tx.AutoMigrate(
&User{},
// all other tables of you app
)
return err
})
if err := m.Migrate(); err != nil {
log.Fatalf("Migration failed: %v", err)
}
log.Println("Migration did run successfully")
However, the sql INSERT INTO user (username) VALUES ('admin')
was not executed as expected.
I then checked the source code of this library. There is only insertMigration
in this place:
Lines 347 to 351 in 293e5ee
for _, migration := range g.migrations { | |
if err := g.insertMigration(migration.ID); err != nil { | |
return err | |
} | |
} |
Is migration.Migrate(g.tx)
missing. Or should it be call g.runMigration(migration.ID)
instead of g.insertMigration(migration.ID)
?
ivanivankovicWindyhe
Metadata
Metadata
Assignees
Labels
No labels