mirror of
https://github.com/pressly/goose.git
synced 2025-05-31 11:42:04 +00:00
GetDBVersion(): report error rather than aborting
This commit is contained in:
parent
8f7107e30a
commit
ae19207fff
@ -20,7 +20,11 @@ func downRun(cmd *Command, args ...string) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
current := goose.GetDBVersion(conf)
|
||||
current, err := goose.GetDBVersion(conf)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if current == 0 {
|
||||
fmt.Println("db is empty, can't go down.")
|
||||
return
|
||||
|
@ -18,7 +18,11 @@ func redoRun(cmd *Command, args ...string) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
target := goose.GetDBVersion(conf)
|
||||
target, err := goose.GetDBVersion(conf)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
_, earliest := goose.GetPreviousDBVersion(conf.MigrationsDir, target)
|
||||
|
||||
downRun(cmd, args...)
|
||||
|
@ -266,20 +266,20 @@ func createVersionTable(conf *DBConf, db *sql.DB) error {
|
||||
|
||||
// wrapper for EnsureDBVersion for callers that don't already have
|
||||
// their own DB instance
|
||||
func GetDBVersion(conf *DBConf) int64 {
|
||||
func GetDBVersion(conf *DBConf) (version int64, err error) {
|
||||
|
||||
db, err := sql.Open(conf.Driver.Name, conf.Driver.OpenStr)
|
||||
if err != nil {
|
||||
log.Fatal("couldn't open DB:", err)
|
||||
return -1, err
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
version, err := EnsureDBVersion(conf, db)
|
||||
version, err = EnsureDBVersion(conf, db)
|
||||
if err != nil {
|
||||
log.Fatalf("couldn't get DB version: %v", err)
|
||||
return -1, err
|
||||
}
|
||||
|
||||
return version
|
||||
return version, nil
|
||||
}
|
||||
|
||||
func GetPreviousDBVersion(dirpath string, version int64) (previous, earliest int64) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user