Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(errors): Add migration name for migrate/rollback errors #11

Merged
merged 1 commit into from
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func main() {
Addr: "localhost:5432",
User: "test_user",
Database: "test",
Password: "",
})

err := migrations.Run(db, directory, os.Args)
Expand Down
4 changes: 2 additions & 2 deletions migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ func migrate(db *pg.DB, directory string) error {
})
}
if err != nil {
return err
return fmt.Errorf("%s: %s", m.Name, err)
}

m.CompletedAt = time.Now()
err = db.Insert(&m)
if err != nil {
return err
return fmt.Errorf("%s: %s", m.Name, err)
}
fmt.Printf("Finished running %q\n", m.Name)
}
Expand Down
4 changes: 2 additions & 2 deletions migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func TestMigrate(t *testing.T) {
}

err := migrate(db, tmp)
assert.EqualError(tt, err, "error")
assert.EqualError(tt, err, "123: error")

assertTable(tt, db, "test_table", false)
})
Expand All @@ -171,7 +171,7 @@ func TestMigrate(t *testing.T) {
}

err := migrate(db, tmp)
assert.EqualError(tt, err, "error")
assert.EqualError(tt, err, "123: error")

assertTable(tt, db, "test_table", true)
})
Expand Down
4 changes: 2 additions & 2 deletions rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ func rollback(db *pg.DB, directory string) error {
})
}
if err != nil {
return err
return fmt.Errorf("%s: %s", m.Name, err)
}

_, err = db.Model(&m).Where("name = ?", m.Name).Delete()
if err != nil {
return err
return fmt.Errorf("%s: %s", m.Name, err)
}
fmt.Printf("Finished rolling back %q\n", m.Name)
}
Expand Down
4 changes: 2 additions & 2 deletions rollback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestRollback(t *testing.T) {
assert.Nil(tt, err)

err = rollback(db, tmp)
assert.EqualError(tt, err, "error")
assert.EqualError(tt, err, "123: error")

assertTable(tt, db, "test_table", false)
})
Expand All @@ -124,7 +124,7 @@ func TestRollback(t *testing.T) {
assert.Nil(tt, err)

err = rollback(db, tmp)
assert.EqualError(tt, err, "error")
assert.EqualError(tt, err, "123: error")

assertTable(tt, db, "test_table", true)
})
Expand Down