diff --git a/cli/main.go b/cli/main.go index 278d1349..58b17c15 100644 --- a/cli/main.go +++ b/cli/main.go @@ -5,7 +5,6 @@ import ( "fmt" "os" "os/signal" - "path/filepath" "strconv" "syscall" "time" @@ -70,7 +69,7 @@ Commands: // translate -path into -source if given if *sourcePtr == "" && *pathPtr != "" { - *sourcePtr = fmt.Sprintf("file://%v", filepath.Clean(*pathPtr)) + *sourcePtr = fmt.Sprintf("file://%v", *pathPtr) } // initialize migrate diff --git a/database/mysql/mysql.go b/database/mysql/mysql.go index 201da6e4..b87a276c 100644 --- a/database/mysql/mysql.go +++ b/database/mysql/mysql.go @@ -291,15 +291,13 @@ func (m *Mysql) Drop() error { func (m *Mysql) ensureVersionTable() error { // check if migration table exists - var count int - query := `SHOW TABLES WHERE ?` - if err := m.db.QueryRow(query, m.config.MigrationsTable).Scan(&count); err != nil { + var result string + query := `SHOW TABLES LIKE "` + m.config.MigrationsTable + `"` + if err := m.db.QueryRow(query).Scan(&result); err != nil { if err != sql.ErrNoRows { return &database.Error{OrigErr: err, Query: []byte(query)} } - } - - if count == 1 { + } else { return nil } diff --git a/database/mysql/mysql_test.go b/database/mysql/mysql_test.go index d9262ddb..3eb22ef0 100644 --- a/database/mysql/mysql_test.go +++ b/database/mysql/mysql_test.go @@ -47,5 +47,14 @@ func Test(t *testing.T) { t.Fatalf("%v", err) } dt.Test(t, d, []byte("SELECT 1")) + + // check ensureVersionTable + if err := d.(*Mysql).ensureVersionTable(); err != nil { + t.Fatal(err) + } + // check again + if err := d.(*Mysql).ensureVersionTable(); err != nil { + t.Fatal(err) + } }) }