Fix issue with migration when it fails (#3)

Instead of using the transaction to call Exec, the database is used which causes the rollback to not revert the new migration row.
This commit is contained in:
siddweiker 2021-08-18 17:30:04 -04:00 committed by GitHub
parent ac09d418c1
commit 34a9ee7d2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -107,7 +107,7 @@ func (s *Sqlx) runMigration(db *sqlx.DB, m SqlxMigration) error {
if err != nil {
return errorf(err)
}
_, err = db.Exec("INSERT INTO migrations (id) VALUES ($1)", m.ID)
_, err = tx.Exec("INSERT INTO migrations (id) VALUES ($1)", m.ID)
if err != nil {
tx.Rollback()
return errorf(err)
@ -131,7 +131,7 @@ func (s *Sqlx) runRollback(db *sqlx.DB, m SqlxMigration) error {
if err != nil {
return errorf(err)
}
_, err = db.Exec("DELETE FROM migrations WHERE id=$1", m.ID)
_, err = tx.Exec("DELETE FROM migrations WHERE id=$1", m.ID)
if err != nil {
tx.Rollback()
return errorf(err)