diff --git a/cli/main.go b/cli/main.go index 278d134..58b17c1 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 201da6e..b87a276 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 d9262dd..3eb22ef 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) + } }) }