migration: allow database/sql to do type conversion to avoid dialect differences

pull/2/head
Liam Staskawicz 2013-06-30 11:38:24 -07:00
parent d5427607db
commit f8e86e3745
2 changed files with 4 additions and 7 deletions

View File

@ -76,7 +76,6 @@ import (
"database/sql"
_ "{{.Driver.Import}}"
"log"
"fmt"
)
func main() {
@ -94,9 +93,8 @@ func main() {
{{ .Func }}(txn)
// XXX: drop goose_db_version table on some minimum version number?
versionFmt := "INSERT INTO goose_db_version (version_id, is_applied) VALUES (%v, %t);"
versionStmt := fmt.Sprintf(versionFmt, int64({{ .Version }}), {{ .Direction }})
if _, err = txn.Exec(versionStmt); err != nil {
stmt := "INSERT INTO goose_db_version (version_id, is_applied) VALUES ($1, $2);"
if _, err = txn.Exec(stmt, {{ .Version }}, {{ .Direction }}); err != nil {
txn.Rollback()
log.Fatal("failed to write version: ", err)
}

View File

@ -2,7 +2,6 @@ package main
import (
"database/sql"
"fmt"
"io/ioutil"
"log"
"path/filepath"
@ -84,8 +83,8 @@ func runSQLMigration(db *sql.DB, script string, v int64, direction bool) error {
func finalizeMigration(txn *sql.Tx, direction bool, v int64) error {
// XXX: drop goose_db_version table on some minimum version number?
versionStmt := fmt.Sprintf("INSERT INTO goose_db_version (version_id, is_applied) VALUES (%d, %t);", v, direction)
if _, err := txn.Exec(versionStmt); err != nil {
stmt := "INSERT INTO goose_db_version (version_id, is_applied) VALUES ($1, $2)"
if _, err := txn.Exec(stmt, v, direction); err != nil {
txn.Rollback()
return err
}