gonews/vendor/github.com/pressly/goose/redo.go

34 lines
553 B
Go
Raw Normal View History

2019-09-09 21:52:32 +05:00
package goose
import (
"database/sql"
)
// Redo rolls back the most recently applied migration, then runs it again.
func Redo(db *sql.DB, dir string) error {
currentVersion, err := GetDBVersion(db)
if err != nil {
return err
}
migrations, err := CollectMigrations(dir, minVersion, maxVersion)
if err != nil {
return err
}
current, err := migrations.Current(currentVersion)
if err != nil {
return err
}
if err := current.Down(db); err != nil {
return err
}
if err := current.Up(db); err != nil {
return err
}
return nil
}