You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollback isn't executed when an error occured in the migration script. The issue have been raised in #42 but the solution provided isn't working as expected because RollbackLast only rollback the last succeed migration, not the last that have failed :( .
Dependencies
gorm.io (so v2) version: v1.21.12
go migrate version: v2.0.0
postgresql 12
go version: 1.16
Migrations
package main
varMigrations= []*gormigrate.Migration{
{
ID: "2021082409555553",
Migrate: func(tx*gorm.DB) error {
returntx.Exec(`ALTER TABLE "todos" ALTER COLUMN "text" TYPE varchar(200)`).Error
},
Rollback: func(tx*gorm.DB) error {
returntx.Exec(`ALTER TABLE "MMMMMMM" ALTER COLUMN "text" TYPE varchar(200)`).Error
},
},
}
Execute Migrate
package main
funcMigrate(db*gorm.DB) error {
m:=gormigrate.New(db, gormigrate.DefaultOptions, Migrations)
returnm.Migrate()
}
Actual
The migration function is called, fails because the todos table doesn't exist and the rollback function isn't called.
Note: Logs have been wrapped with logrus
DEBU[0000] SELECT count(*) FROM "migrations" WHERE id = '2021082409555553' error="<nil>" rows=1
DEBU[0000] ALTER TABLE "todos" ALTER COLUMN "text" TYPE varchar(200) error="ERROR: relation \"todos\" does not exist (SQLSTATE 42P01)" rows=0
FATA[0000] ERROR: relation "todos" does not exist (SQLSTATE 42P01) error="ERROR: relation \"todos\" does not exist (SQLSTATE 42P01)"
Expectations
The first ALTER TABLE will fail because the table doesn't exists and then Rollback function must be called.
Anybody have a clue ?
Thanks !
The text was updated successfully, but these errors were encountered:
Hi everybody,
Rollback isn't executed when an error occured in the migration script. The issue have been raised in #42 but the solution provided isn't working as expected because RollbackLast only rollback the last succeed migration, not the last that have failed :( .
Dependencies
gorm.io (so v2) version: v1.21.12
go migrate version: v2.0.0
postgresql 12
go version: 1.16
Migrations
Execute Migrate
Actual
The migration function is called, fails because the
todos
table doesn't exist and the rollback function isn't called.Note: Logs have been wrapped with logrus
Expectations
The first
ALTER TABLE
will fail because the table doesn't exists and then Rollback function must be called.Anybody have a clue ?
Thanks !
The text was updated successfully, but these errors were encountered: