diff --git a/README.md b/README.md index c76da3f..aaaa334 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,12 @@ Goose is a database migration tool. Manage your database's evolution by creating This is a fork of https://bitbucket.org/liamstask/goose with the following changes: - No config files -- Default binary can migrate SQL files only, we dropped building .go files on-the-fly -- Import goose pkg to run complex Go migrations with your own `*sql.DB` connection (no pkg dependency hell anymore) +- Default goose binary can migrate SQL files only +- We dropped building .go files on-the-fly in favor of the below +- Import `github.com/pressly/goose` package + - To run complex Go migrations with your own `*sql.DB` connection via `*sql.Tx` transactions + - The pkg doesn't register any SQL drivers anymore (no `panic()` driver conflicts with your codebase!) + - The pkg doesn't have any vendor dependencies anymore # Install diff --git a/dialect.go b/dialect.go index 6070e73..536152b 100644 --- a/dialect.go +++ b/dialect.go @@ -3,8 +3,6 @@ package goose import ( "database/sql" "fmt" - - "github.com/mattn/go-sqlite3" ) // SqlDialect abstracts the details of specific SQL dialects @@ -58,12 +56,8 @@ func (pg PostgresDialect) insertVersionSql() string { func (pg PostgresDialect) dbVersionQuery(db *sql.DB) (*sql.Rows, error) { rows, err := db.Query("SELECT version_id, is_applied from goose_db_version ORDER BY id DESC") - - // XXX: check for postgres specific error indicating the table doesn't exist. - // for now, assume any error is because the table doesn't exist, - // in which case we'll try to create it. if err != nil { - return nil, ErrTableDoesNotExist + return nil, err } return rows, err @@ -91,12 +85,8 @@ func (m MySqlDialect) insertVersionSql() string { func (m MySqlDialect) dbVersionQuery(db *sql.DB) (*sql.Rows, error) { rows, err := db.Query("SELECT version_id, is_applied from goose_db_version ORDER BY id DESC") - - // XXX: check for mysql specific error indicating the table doesn't exist. - // for now, assume any error is because the table doesn't exist, - // in which case we'll try to create it. if err != nil { - return nil, ErrTableDoesNotExist + return nil, err } return rows, err @@ -123,10 +113,9 @@ func (m Sqlite3Dialect) insertVersionSql() string { func (m Sqlite3Dialect) dbVersionQuery(db *sql.DB) (*sql.Rows, error) { rows, err := db.Query("SELECT version_id, is_applied from goose_db_version ORDER BY id DESC") - - switch err.(type) { - case sqlite3.Error: - return nil, ErrTableDoesNotExist + if err != nil { + return nil, err } + return rows, err } diff --git a/migrate.go b/migrate.go index 0a6a8dd..2d4e582 100644 --- a/migrate.go +++ b/migrate.go @@ -16,7 +16,6 @@ import ( ) var ( - ErrTableDoesNotExist = errors.New("table does not exist") ErrNoPreviousVersion = errors.New("no previous version found") goMigrations []*Migration ) @@ -213,10 +212,7 @@ func EnsureDBVersion(db *sql.DB) (int64, error) { rows, err := GetDialect().dbVersionQuery(db) if err != nil { - if err == ErrTableDoesNotExist { - return 0, createVersionTable(db) - } - return 0, err + return 0, createVersionTable(db) } defer rows.Close()