Merge pull request #48 from nkovacs/47-migrate-to-0

Allow down-to to roll back first version
This commit is contained in:
Vojtech Vitek 2017-06-19 16:14:23 -04:00 committed by GitHub
commit 43bbf73c63

16
down.go
View File

@ -38,23 +38,15 @@ func DownTo(db *sql.DB, dir string, version int64) error {
return err
}
prev, err := migrations.Previous(currentVersion)
current, err := migrations.Current(currentVersion)
if err != nil {
if err == ErrNoNextVersion {
fmt.Printf("goose: no migrations to run. current version: %d\n", currentVersion)
return nil
}
return err
}
if prev.Version < version {
fmt.Printf("goose: no migrations to run. current version: %d\n", currentVersion)
return nil
}
current, err := migrations.Current(currentVersion)
if err != nil {
return fmt.Errorf("no migration %v", currentVersion)
if current.Version <= version {
fmt.Printf("goose: no migrations to run. current version: %d\n", currentVersion)
return nil
}
if err = current.Down(db); err != nil {