Skip to content
This repository has been archived by the owner on Jun 28, 2018. It is now read-only.

Commit

Permalink
remove cleanpath, fix mysql ensureVersionTable
Browse files Browse the repository at this point in the history
  • Loading branch information
mattes committed Mar 1, 2017
1 parent 150ac7d commit 1f37f41
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
3 changes: 1 addition & 2 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"os"
"os/signal"
"path/filepath"
"strconv"
"syscall"
"time"
Expand Down Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions database/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
9 changes: 9 additions & 0 deletions database/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}

0 comments on commit 1f37f41

Please sign in to comment.