This commit is contained in:
mattes 2014-12-19 02:40:11 -08:00
parent 6b535262fd
commit 3ce2dc92c2
1 changed files with 29 additions and 8 deletions

37
main.go
View File

@ -63,8 +63,11 @@ func main() {
timerStart = time.Now()
pipe := pipep.New()
go migrate.Migrate(pipe, *url, *migrationsPath, relativeNInt)
writePipe(pipe)
ok := writePipe(pipe)
printTimer()
if !ok {
os.Exit(1)
}
case "goto":
verifyMigrationsPath(*migrationsPath)
@ -86,40 +89,55 @@ func main() {
timerStart = time.Now()
pipe := pipep.New()
go migrate.Migrate(pipe, *url, *migrationsPath, relativeNInt)
writePipe(pipe)
ok := writePipe(pipe)
printTimer()
if !ok {
os.Exit(1)
}
case "up":
verifyMigrationsPath(*migrationsPath)
timerStart = time.Now()
pipe := pipep.New()
go migrate.Up(pipe, *url, *migrationsPath)
writePipe(pipe)
ok := writePipe(pipe)
printTimer()
if !ok {
os.Exit(1)
}
case "down":
verifyMigrationsPath(*migrationsPath)
timerStart = time.Now()
pipe := pipep.New()
go migrate.Down(pipe, *url, *migrationsPath)
writePipe(pipe)
ok := writePipe(pipe)
printTimer()
if !ok {
os.Exit(1)
}
case "redo":
verifyMigrationsPath(*migrationsPath)
timerStart = time.Now()
pipe := pipep.New()
go migrate.Redo(pipe, *url, *migrationsPath)
writePipe(pipe)
ok := writePipe(pipe)
printTimer()
if !ok {
os.Exit(1)
}
case "reset":
verifyMigrationsPath(*migrationsPath)
timerStart = time.Now()
pipe := pipep.New()
go migrate.Reset(pipe, *url, *migrationsPath)
writePipe(pipe)
ok := writePipe(pipe)
printTimer()
if !ok {
os.Exit(1)
}
case "version":
verifyMigrationsPath(*migrationsPath)
@ -137,13 +155,14 @@ func main() {
}
}
func writePipe(pipe chan interface{}) {
func writePipe(pipe chan interface{}) bool {
errorFlag := false
if pipe != nil {
for {
select {
case item, ok := <-pipe:
if !ok {
return
return errorFlag
} else {
switch item.(type) {
@ -153,6 +172,7 @@ func writePipe(pipe chan interface{}) {
case error:
c := color.New(color.FgRed)
c.Println(item.(error).Error(), "\n")
errorFlag = true
case file.File:
f := item.(file.File)
@ -172,6 +192,7 @@ func writePipe(pipe chan interface{}) {
}
}
}
return false
}
func verifyMigrationsPath(path string) {