mirror of
https://github.com/pressly/goose.git
synced 2025-05-31 11:42:04 +00:00
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.
38 lines
697 B
Go
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
|
|
}
|