-
Notifications
You must be signed in to change notification settings - Fork 23
/
manage.go
54 lines (50 loc) · 1.12 KB
/
manage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import "github.com/LunaNode/lobster"
import "github.com/mattes/migrate/migrate"
import "github.com/mattes/migrate/migrate/direction"
import "github.com/mattes/migrate/file"
import pipep "github.com/mattes/migrate/pipe"
import _ "github.com/mattes/migrate/driver/mysql"
import "fmt"
import "os"
func main() {
cfgPath := "lobster.cfg"
if len(os.Args) >= 2 {
cfgPath = os.Args[1]
}
lobster.Setup(cfgPath)
url := "mysql://" + lobster.GetDatabaseString()
pipe := pipep.New()
go migrate.Up(pipe, url, "./db/migrations")
hadError := false
done := false
for !done {
select {
case item, more := <-pipe:
if !more {
done = true
} else {
switch item.(type) {
case string:
fmt.Println(item.(string))
case error:
fmt.Printf("ERROR: %v\n", item)
hadError = true
case file.File:
f := item.(file.File)
if f.Direction == direction.Up {
fmt.Print("> ")
} else if f.Direction == direction.Down {
fmt.Print("< ")
}
fmt.Println(f.FileName)
default:
fmt.Printf("%v", item)
}
}
}
}
if !hadError {
fmt.Println("database up to date")
}
}