mirror of
https://github.com/pressly/goose.git
synced 2025-05-22 15:29:53 +00:00
reorg: plumb dbconf through to consumers that need it for dialect-specific operations
This commit is contained in:
parent
bb38ea2554
commit
161a0a1cc2
@ -42,7 +42,7 @@ func statusRun(cmd *Command, args ...string) {
|
|||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
// must ensure that the version table exists if we're running on a pristine DB
|
// must ensure that the version table exists if we're running on a pristine DB
|
||||||
if _, e := ensureDBVersion(db); e != nil {
|
if _, e := ensureDBVersion(conf, db); e != nil {
|
||||||
log.Fatal(e)
|
log.Fatal(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
migrate.go
12
migrate.go
@ -48,7 +48,7 @@ func runMigrations(conf *DBConf, migrationsDir string, target int64) {
|
|||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
current, e := ensureDBVersion(db)
|
current, e := ensureDBVersion(conf, db)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
log.Fatalf("couldn't get DB version: %v", e)
|
log.Fatalf("couldn't get DB version: %v", e)
|
||||||
}
|
}
|
||||||
@ -190,13 +190,13 @@ func numericComponent(name string) (int64, error) {
|
|||||||
|
|
||||||
// retrieve the current version for this DB.
|
// retrieve the current version for this DB.
|
||||||
// Create and initialize the DB version table if it doesn't exist.
|
// Create and initialize the DB version table if it doesn't exist.
|
||||||
func ensureDBVersion(db *sql.DB) (int64, error) {
|
func ensureDBVersion(conf *DBConf, db *sql.DB) (int64, error) {
|
||||||
|
|
||||||
rows, err := db.Query("SELECT version_id, is_applied from goose_db_version ORDER BY id DESC;")
|
rows, err := db.Query("SELECT version_id, is_applied from goose_db_version ORDER BY id DESC;")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// XXX: cross platform method to detect failure reason
|
// XXX: cross platform method to detect failure reason
|
||||||
// for now, assume it was because the table didn't exist, and try to create it
|
// for now, assume it was because the table didn't exist, and try to create it
|
||||||
return 0, createVersionTable(db)
|
return 0, createVersionTable(conf, db)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The most recent record for each migration specifies
|
// The most recent record for each migration specifies
|
||||||
@ -235,7 +235,9 @@ func ensureDBVersion(db *sql.DB) (int64, error) {
|
|||||||
panic("failure in ensureDBVersion()")
|
panic("failure in ensureDBVersion()")
|
||||||
}
|
}
|
||||||
|
|
||||||
func createVersionTable(db *sql.DB) error {
|
// Create the goose_db_version table
|
||||||
|
// and insert the initial 0 value into it
|
||||||
|
func createVersionTable(conf *DBConf, db *sql.DB) error {
|
||||||
txn, err := db.Begin()
|
txn, err := db.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -271,7 +273,7 @@ func getDBVersion(conf *DBConf) int64 {
|
|||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
version, err := ensureDBVersion(db)
|
version, err := ensureDBVersion(conf, db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("couldn't get DB version: %v", err)
|
log.Fatalf("couldn't get DB version: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user