mirror of https://github.com/pressly/goose.git
reorg: move getDBVersion() into migrate to clarify that it's common functionality
parent
fe14d0a1f5
commit
dc913a5569
17
down.go
17
down.go
|
@ -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
|
||||
|
|
18
migrate.go
18
migrate.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue