Add status command to show the current state of a database wrt. migrations.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
# Package
|
# Package
|
||||||
|
|
||||||
bin = @["db_migrate"]
|
bin = @["db_migrate"]
|
||||||
version = "0.4.0"
|
version = "0.4.1"
|
||||||
author = "Jonathan Bernard"
|
author = "Jonathan Bernard"
|
||||||
description = "Simple tool to handle database migrations."
|
description = "Simple tool to handle database migrations."
|
||||||
license = "BSD"
|
license = "BSD"
|
||||||
|
@@ -171,7 +171,7 @@ proc up*(
|
|||||||
|
|
||||||
# Apply each of the migrations.
|
# Apply each of the migrations.
|
||||||
for migration in toRun:
|
for migration in toRun:
|
||||||
info migration.name
|
info "Applying up script for " & migration.name
|
||||||
|
|
||||||
if not migration.upPath.fileExists:
|
if not migration.upPath.fileExists:
|
||||||
pgConn.rollbackWithErr "Can not find UP file for " & migration.name &
|
pgConn.rollbackWithErr "Can not find UP file for " & migration.name &
|
||||||
@@ -202,7 +202,7 @@ proc down*(
|
|||||||
pgConn.exec(sql"BEGIN")
|
pgConn.exec(sql"BEGIN")
|
||||||
|
|
||||||
for migration in migrationsToDown:
|
for migration in migrationsToDown:
|
||||||
info migration.name
|
info "Applying down script for " & migration.name
|
||||||
|
|
||||||
if not migration.downPath.fileExists:
|
if not migration.downPath.fileExists:
|
||||||
pgConn.rollbackWithErr "Can not find DOWN file for " & migration.name &
|
pgConn.rollbackWithErr "Can not find DOWN file for " & migration.name &
|
||||||
@@ -229,6 +229,7 @@ Usage:
|
|||||||
db_migrate [options] up [<count>]
|
db_migrate [options] up [<count>]
|
||||||
db_migrate [options] down [<count>]
|
db_migrate [options] down [<count>]
|
||||||
db_migrate [options] init <schema-name>
|
db_migrate [options] init <schema-name>
|
||||||
|
db_migrate [options] status
|
||||||
db_migrate (-V | --version)
|
db_migrate (-V | --version)
|
||||||
db_migrate (-h | --help)
|
db_migrate (-h | --help)
|
||||||
|
|
||||||
@@ -249,7 +250,7 @@ Options:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Parse arguments
|
# Parse arguments
|
||||||
let args = docopt(doc, version = "db-migrate (Nim) 0.4.0\nhttps://git.jdb-software.com/jdb/db-migrate")
|
let args = docopt(doc, version = "db-migrate (Nim) 0.4.1\nhttps://git.jdb-software.com/jdb/db-migrate")
|
||||||
|
|
||||||
let exitErr = proc(msg: string): void =
|
let exitErr = proc(msg: string): void =
|
||||||
fatal("db_migrate: " & msg)
|
fatal("db_migrate: " & msg)
|
||||||
@@ -331,6 +332,21 @@ Options:
|
|||||||
except DbError:
|
except DbError:
|
||||||
exitErr "Unable to migrate database: " & getCurrentExceptionMsg()
|
exitErr "Unable to migrate database: " & getCurrentExceptionMsg()
|
||||||
|
|
||||||
|
elif args["status"]:
|
||||||
|
|
||||||
|
info "Database Migration Status" &
|
||||||
|
"\n\nSQL Migration Folders: " & join(config.sqlDirs.mapIt("\n " & it), "") &
|
||||||
|
"\n\nMigrations: " &
|
||||||
|
"\n available: " & join(
|
||||||
|
toSeq(available.keys)
|
||||||
|
.sorted(system.cmp)
|
||||||
|
.mapIt("\n " & it),
|
||||||
|
"") &
|
||||||
|
"\n run: " & join(run.mapIt("\n " & it), "") &
|
||||||
|
"\n notRun: " & join(notRun.mapIt("\n " & it.name), "") &
|
||||||
|
"\n missing: " & join(missing.mapIt("\n " & it.name), "") &
|
||||||
|
"\n"
|
||||||
|
|
||||||
elif args["init"]: discard
|
elif args["init"]: discard
|
||||||
|
|
||||||
let newResults = diffMigrations(pgConn, config)
|
let newResults = diffMigrations(pgConn, config)
|
||||||
|
Reference in New Issue
Block a user