reorg: move getDBVersion() into migrate to clarify that it's common functionality

pull/2/head
Liam Staskawicz 2012-12-24 10:18:24 -08:00
parent fe14d0a1f5
commit dc913a5569
2 changed files with 18 additions and 17 deletions

17
down.go
View File

@ -1,7 +1,6 @@
package main
import (
"database/sql"
"fmt"
"log"
"os"
@ -39,22 +38,6 @@ func downRun(cmd *Command, args ...string) {
runMigrations(conf, conf.MigrationsDir, previous)
}
func getDBVersion(conf *DBConf) int {
db, err := sql.Open(conf.Driver, conf.OpenStr)
if err != nil {
log.Fatal("couldn't open DB:", err)
}
defer db.Close()
version, err := ensureDBVersion(db)
if err != nil {
log.Fatalf("couldn't get DB version: %v", err)
}
return version
}
func getPreviousVersion(dirpath string, version int) (previous, earliest int) {
previous = -1

View File

@ -232,3 +232,21 @@ func ensureDBVersion(db *sql.DB) (int, error) {
return 0, txn.Commit()
}
// wrapper for ensureDBVersion for callers that don't already have
// their own DB instance
func getDBVersion(conf *DBConf) int {
db, err := sql.Open(conf.Driver, conf.OpenStr)
if err != nil {
log.Fatal("couldn't open DB:", err)
}
defer db.Close()
version, err := ensureDBVersion(db)
if err != nil {
log.Fatalf("couldn't get DB version: %v", err)
}
return version
}