Skip to content

Commit

Permalink
Add "goto" command
Browse files Browse the repository at this point in the history
  • Loading branch information
fronik committed Sep 30, 2014
1 parent b4a84d2 commit 9ba9fe8
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <n>.")
fmt.Println("Unable to parse param <n>.")
os.Exit(1)
}
timerStart = time.Now()
Expand All @@ -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 <v>.")
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()
Expand Down Expand Up @@ -181,6 +204,7 @@ Commands:
redo Roll back most recent migration, then apply it again
version Show current migration version
migrate <n> Apply migrations -n|+n
goto <v> Migrate to version v
help Show this help
'-path' defaults to current working directory.
Expand Down

0 comments on commit 9ba9fe8

Please sign in to comment.