mirror of https://github.com/pressly/goose.git
Fix transaction on nil Go func migrations
parent
ae64375f29
commit
946d2ad074
22
migrate.go
22
migrate.go
|
@ -81,23 +81,21 @@ func RunMigrations(db *sql.DB, dir string, target int64) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
case ".go":
|
case ".go":
|
||||||
fn := m.Up
|
|
||||||
if !direction {
|
|
||||||
fn = m.Down
|
|
||||||
}
|
|
||||||
if fn == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
tx, err := db.Begin()
|
tx, err := db.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("db.Begin: ", err)
|
log.Fatal("db.Begin: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := fn(tx); err != nil {
|
fn := m.Up
|
||||||
tx.Rollback()
|
if !direction {
|
||||||
log.Fatalf("FAIL %s (%v), quitting migration.", filepath.Base(m.Source), err)
|
fn = m.Down
|
||||||
return err
|
}
|
||||||
|
if fn != nil {
|
||||||
|
if err := fn(tx); err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
log.Fatalf("FAIL %s (%v), quitting migration.", filepath.Base(m.Source), err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = FinalizeMigration(tx, direction, m.Version); err != nil {
|
if err = FinalizeMigration(tx, direction, m.Version); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue