goose/cmd/goose/cmd_redo.go
Liam Staskawicz e5a160a313 GetPreviousDBVersion(): api cleanup, don't return 'earliest' but do return error
callers of this function shouldn't be concerned with the earliest possible DB version, but we do want a way to return an error if we don't find any valid previous versions. this cleans up the 'down' and 'redo' commands.
2013-09-30 15:20:30 -07:00

38 lines
697 B
Go

package main
import (
"bitbucket.org/liamstask/goose/lib/goose"
"log"
)
var redoCmd = &Command{
Name: "redo",
Usage: "",
Summary: "Re-run the latest migration",
Help: `redo extended help here...`,
}
func redoRun(cmd *Command, args ...string) {
conf, err := goose.NewDBConf(*flagPath, *flagEnv)
if err != nil {
log.Fatal(err)
}
current, err := goose.GetDBVersion(conf)
if err != nil {
log.Fatal(err)
}
previous, err := goose.GetPreviousDBVersion(conf.MigrationsDir, current)
if err != nil {
log.Fatal(err)
}
goose.RunMigrations(conf, conf.MigrationsDir, previous)
goose.RunMigrations(conf, conf.MigrationsDir, current)
}
func init() {
redoCmd.Run = redoRun
}