Merge pull request #14 from vkonstantin/feature/migrateTo

Add goto command
This commit is contained in:
Matthias Kadenbach 2014-10-04 09:44:10 +02:00
commit e89512949c
1 changed files with 25 additions and 1 deletions

26
main.go
View File

@ -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()
@ -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()
@ -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.