Make this all work

pull/157/head
Vojtech Vitek 2019-03-06 01:20:06 -05:00
parent 0cdcc45122
commit 5cd6f8c9d0
7 changed files with 27 additions and 24 deletions

View File

@ -32,7 +32,7 @@ This will install the `goose` binary to your `$GOPATH/bin` directory.
For a lite version of the binary without DB connection dependent commands, use the exclusive build tags:
$ go build -tags='no_mysql no_sqlite no_psql' -i -o goose ./cmd/goose
$ go build -tags='no_postgres no_mysql no_sqlite3' -i -o goose ./cmd/goose
# Usage

View File

@ -1,4 +1,4 @@
// +build mysql
// +build !no_mysql
package main
@ -15,19 +15,22 @@ import (
// the parameter `parseTime` set to true. This allows internal goose logic
// to assume that DATETIME/DATE/TIMESTAMP can be scanned into the time.Time
// type.
func normalizeDBString(str string) string {
var err error
str, err = normalizeMySQLDSN(dns string)
if err != nil {
log.Fatalf("failed to normalize MySQL connection string: %v", err)
func normalizeDBString(driver string, str string) string {
if driver == "mysql" {
var err error
str, err = normalizeMySQLDSN(str)
if err != nil {
log.Fatalf("failed to normalize MySQL connection string: %v", err)
}
}
return str
}
func normalizeMySQLDSN(dns string) (string, error) {
config, err := mysql.ParseDSN(dsn)
if err != nil {
return "", err
}
config.ParseTime = true
return config.FormatDSN(), nil
func normalizeMySQLDSN(dsn string) (string, error) {
config, err := mysql.ParseDSN(dsn)
if err != nil {
return "", err
}
config.ParseTime = true
return config.FormatDSN(), nil
}

View File

@ -1,4 +1,4 @@
// +build !mysql
// +build no_mysql
package main
@ -7,6 +7,6 @@ import (
_ "github.com/ziutek/mymysql/godrv"
)
func normalizeDBString(str string) string {
func normalizeDBString(driver string, str string) string {
return str
}

View File

@ -1,4 +1,4 @@
// +build !no_pq
// +build !no_postgres
package main

View File

@ -1,4 +1,4 @@
// +build !no_sqlite
// +build !no_sqlite3
package main

View File

@ -55,7 +55,7 @@ func main() {
driver, dbstring, command := args[0], args[1], args[2]
db, err := goose.OpenDBWithDriver(driver, normalizeDBString(dbstring))
db, err := goose.OpenDBWithDriver(driver, normalizeDBString(driver, dbstring))
if err != nil {
log.Fatalf("-dbstring=%q: %v\n", dbstring, err)
}

View File

@ -47,20 +47,20 @@ func TestLiteBinary(t *testing.T) {
t.Fatal(err)
}
defer os.RemoveAll(dir) // clean up
defer os.Remove("./bin/light-goose") // clean up
defer os.RemoveAll(dir) // clean up
defer os.Remove("./bin/lite-goose") // clean up
// this has to be done outside of the loop
// since go only supports space separated tags list.
cmd := exec.Command("go", "build", "-tags='no_mysql no_sqlite no_psql'", "-o", "./bin/light-goose", "./cmd/goose")
cmd := exec.Command("go", "build", "-tags='no_postgres no_mysql no_sqlite3'", "-o", "./bin/lite-goose", "./cmd/goose")
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("%s:\n%v\n\n%s", err, cmd, out)
}
commands := []string{
fmt.Sprintf("./bin/light-goose -dir=%s create user_indices sql", dir),
fmt.Sprintf("./bin/light-goose -dir=%s fix", dir),
fmt.Sprintf("./bin/lite-goose -dir=%s create user_indices sql", dir),
fmt.Sprintf("./bin/lite-goose -dir=%s fix", dir),
}
for _, cmd := range commands {