From 9ba9fe85e673da4e00f4526d20c2d2d30e2d4a62 Mon Sep 17 00:00:00 2001 From: fronik Date: Thu, 25 Sep 2014 20:43:08 +0400 Subject: [PATCH] Add "goto" command --- main.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index c2d24d00e..c42aced69 100644 --- a/main.go +++ b/main.go @@ -57,7 +57,7 @@ func main() { relativeN := flag.Arg(1) relativeNInt, err := strconv.Atoi(relativeN) if err != nil { - fmt.Println("Unable to parse parse param .") + fmt.Println("Unable to parse param .") os.Exit(1) } timerStart = time.Now() @@ -66,6 +66,29 @@ func main() { writePipe(pipe) printTimer() + case "goto": + verifyMigrationsPath(*migrationsPath) + toVerion := flag.Arg(1) + toVerionInt, err := strconv.Atoi(toVerion) + if err != nil || toVerionInt < 0 { + fmt.Println("Unable to parse param .") + os.Exit(1) + } + + currentVersion, err := migrate.Version(*url, *migrationsPath) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + + relativeNInt := toVerionInt - int(currentVersion) + + timerStart = time.Now() + pipe := pipep.New() + go migrate.Migrate(pipe, *url, *migrationsPath, relativeNInt) + writePipe(pipe) + printTimer() + case "up": verifyMigrationsPath(*migrationsPath) timerStart = time.Now() @@ -181,6 +204,7 @@ Commands: redo Roll back most recent migration, then apply it again version Show current migration version migrate Apply migrations -n|+n + goto Migrate to version v help Show this help '-path' defaults to current working directory.