remove cleanpath, fix mysql ensureVersionTable

This commit is contained in:
Matthias Kadenbach 2017-03-01 11:48:38 -08:00
parent 150ac7d708
commit 1f37f41ee8
No known key found for this signature in database
GPG Key ID: DC1F4DC6D31A7031
3 changed files with 14 additions and 8 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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)
}
})
}