Fix transaction on nil Go func migrations

pull/4/head
Vojtech Vitek (V-Teq) 2016-03-08 12:40:16 -05:00
parent ae64375f29
commit 946d2ad074
1 changed files with 10 additions and 12 deletions

View File

@ -81,23 +81,21 @@ 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)
}
if err := fn(tx); err != nil {
tx.Rollback()
log.Fatalf("FAIL %s (%v), quitting migration.", filepath.Base(m.Source), err)
return 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 {