This repository has been archived by the owner on Jul 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmigrate.go
97 lines (83 loc) · 1.87 KB
/
migrate.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package cmd
import (
"fmt"
"net/url"
"os"
"time"
"github.com/fatih/color"
"github.com/prest/config"
"github.com/spf13/cobra"
// postgres driver for migrate
_ "gopkg.in/mattes/migrate.v1/driver/postgres"
"gopkg.in/mattes/migrate.v1/file"
"gopkg.in/mattes/migrate.v1/migrate/direction"
)
var (
urlConn string
path string
)
// migrateCmd represents the migrate command
var migrateCmd = &cobra.Command{
Use: "migrate",
Short: "Execute migration operations",
Long: `Execute migration operations`,
}
func driverURL() string {
return fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=%s",
url.PathEscape(config.PrestConf.PGUser),
url.PathEscape(config.PrestConf.PGPass),
url.PathEscape(config.PrestConf.PGHost),
config.PrestConf.PGPort,
url.PathEscape(config.PrestConf.PGDatabase),
url.QueryEscape(config.PrestConf.SSLMode))
}
func writePipe(pipe chan interface{}) (ok bool) {
okFlag := true
if pipe != nil {
for {
select {
case item, more := <-pipe:
if more {
switch item.(type) {
case string:
fmt.Println(item.(string))
case error:
c := color.New(color.FgRed)
c.Println(item.(error).Error())
okFlag = false
case file.File:
f := item.(file.File)
c := color.New(color.FgBlue)
if f.Direction == direction.Up {
c.Print(">")
} else if f.Direction == direction.Down {
c.Print("<")
}
fmt.Printf(" %s\n", f.FileName)
default:
text := fmt.Sprint(item)
fmt.Println(text)
}
} else {
return okFlag
}
}
}
}
return okFlag
}
var timerStart time.Time
func printTimer() {
diff := time.Now().Sub(timerStart).Seconds()
if diff > 60 {
fmt.Printf("\n%.4f minutes\n", diff/60)
} else {
fmt.Printf("\n%.4f seconds\n", diff)
}
}
func verifyMigrationsPath(path string) {
if path == "" {
fmt.Println("Please specify path")
os.Exit(-1)
}
}