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:
parent
ac09d418c1
commit
34a9ee7d2b
1 changed files with 2 additions and 2 deletions
4
sqlx.go
4
sqlx.go
|
@ -107,7 +107,7 @@ func (s *Sqlx) runMigration(db *sqlx.DB, m SqlxMigration) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errorf(err)
|
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 {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return errorf(err)
|
return errorf(err)
|
||||||
|
@ -131,7 +131,7 @@ func (s *Sqlx) runRollback(db *sqlx.DB, m SqlxMigration) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errorf(err)
|
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 {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return errorf(err)
|
return errorf(err)
|
||||||
|
|
Loading…
Reference in a new issue