From 34a9ee7d2b52f7b9f2261c2b6d9a8a0a83890a7f Mon Sep 17 00:00:00 2001 From: siddweiker Date: Wed, 18 Aug 2021 17:30:04 -0400 Subject: [PATCH] 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. --- sqlx.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sqlx.go b/sqlx.go index a624f60..3133e20 100644 --- a/sqlx.go +++ b/sqlx.go @@ -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)