Skip to content

Commit

Permalink
results: don't bother counting the number of sql statements. we don't…
Browse files Browse the repository at this point in the history
… have a good way of tracking it for go migrations, and it's not particularly helpful either
  • Loading branch information
liamstask committed Jan 5, 2013
1 parent 0b250b8 commit 77a0382
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
7 changes: 3 additions & 4 deletions migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,22 @@ func runMigrations(conf *DBConf, migrationsDir string, target int64) {

for _, v := range mm.Versions {

var numStatements int
var e error

filepath := mm.Migrations[v].Source

switch path.Ext(filepath) {
case ".go":
numStatements, e = runGoMigration(conf, filepath, v, mm.Direction)
e = runGoMigration(conf, filepath, v, mm.Direction)
case ".sql":
numStatements, e = runSQLMigration(db, filepath, v, mm.Direction)
e = runSQLMigration(db, filepath, v, mm.Direction)
}

if e != nil {
log.Fatalf("FAIL %v, quitting migration", e)
}

fmt.Printf("OK %s (%d statements)\n", path.Base(filepath), numStatements)
fmt.Println("OK ", path.Base(filepath))
}
}

Expand Down
4 changes: 2 additions & 2 deletions migration_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func directionStr(direction bool) string {
// original .go migration, and execute it via `go run` along
// with a main() of our own creation.
//
func runGoMigration(conf *DBConf, path string, version int64, direction bool) (int, error) {
func runGoMigration(conf *DBConf, path string, version int64, direction bool) error {

// everything gets written to a temp dir, and zapped afterwards
d, e := ioutil.TempDir("", "goose")
Expand Down Expand Up @@ -73,7 +73,7 @@ func runGoMigration(conf *DBConf, path string, version int64, direction bool) (i
log.Fatal("`go run` failed: ", e)
}

return 0, nil
return nil
}

//
Expand Down
9 changes: 3 additions & 6 deletions migration_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
//
// All statements following an Up or Down directive are grouped together
// until another direction directive is found.
func runSQLMigration(db *sql.DB, script string, v int64, direction bool) (count int, err error) {
func runSQLMigration(db *sql.DB, script string, v int64, direction bool) error {

txn, err := db.Begin()
if err != nil {
Expand All @@ -32,7 +32,6 @@ func runSQLMigration(db *sql.DB, script string, v int64, direction bool) (count
// ensure we don't apply a query until we're sure it's going
// in the direction we're interested in
directionIsActive := false
count = 0

// find each statement, checking annotations for up/down direction
// and execute each of them in the current transaction
Expand All @@ -55,17 +54,15 @@ func runSQLMigration(db *sql.DB, script string, v int64, direction bool) (count
if _, err = txn.Exec(query); err != nil {
txn.Rollback()
log.Fatalf("FAIL %s (%v), quitting migration.", path.Base(script), err)
return count, err
return err
}

count++
}

if err = finalizeMigration(txn, direction, v); err != nil {
log.Fatalf("error finalizing migration %s, quitting. (%v)", path.Base(script), err)
}

return count, nil
return nil
}

// Update the version table for the given migration,
Expand Down

0 comments on commit 77a0382

Please sign in to comment.