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