-
Notifications
You must be signed in to change notification settings - Fork 3
/
entrypoint.go
64 lines (51 loc) · 1.07 KB
/
entrypoint.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
package main
import (
"bytes"
"io"
"log"
"net/url"
"os"
"os/exec"
"strings"
)
func queryEscape(s string) string {
split := strings.Split(s, "://")
usernamePassword := strings.Split(split[1], "@")
password := strings.Split(usernamePassword[0], ":")
replaced := strings.Replace(s, password[1], url.QueryEscape(password[1]), 3)
return replaced
}
func main() {
args := os.Args
arguments := []string{
"-path",
args[1],
"-database",
queryEscape(args[2]),
"-prefetch",
args[3],
"-lock-timeout",
args[4],
}
if len(args[5]) > 0 {
arguments = append(arguments, "-verbose")
}
if len(args[6]) > 0 {
arguments = append(arguments, "-version")
}
arguments = append(arguments, args[7])
cmd := exec.Command("migrate", arguments...)
var stdBuffer bytes.Buffer
mw := io.MultiWriter(os.Stdout, &stdBuffer)
cmd.Stdout = mw
cmd.Stderr = mw
// Execute the command
if err := cmd.Run(); err != nil {
log.Printf("error: %v", err)
exitError, ok := err.(*exec.ExitError)
if ok {
os.Exit(exitError.ExitCode())
}
}
log.Println(stdBuffer.String())
}