mirror of https://github.com/pressly/goose.git
Make this all work
parent
0cdcc45122
commit
5cd6f8c9d0
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// +build !no_pq
|
||||
// +build !no_postgres
|
||||
|
||||
package main
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// +build !no_sqlite
|
||||
// +build !no_sqlite3
|
||||
|
||||
package main
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue