diff --git a/db_migrate.nimble b/db_migrate.nimble index 9119dfa..080d29d 100644 --- a/db_migrate.nimble +++ b/db_migrate.nimble @@ -1,7 +1,7 @@ # Package bin = @["db_migrate"] -version = "0.4.0" +version = "0.4.1" author = "Jonathan Bernard" description = "Simple tool to handle database migrations." license = "BSD" diff --git a/src/main/nim/db_migrate.nim b/src/main/nim/db_migrate.nim index 06f19ea..df34d5a 100644 --- a/src/main/nim/db_migrate.nim +++ b/src/main/nim/db_migrate.nim @@ -171,7 +171,7 @@ proc up*( # Apply each of the migrations. for migration in toRun: - info migration.name + info "Applying up script for " & migration.name if not migration.upPath.fileExists: pgConn.rollbackWithErr "Can not find UP file for " & migration.name & @@ -202,7 +202,7 @@ proc down*( pgConn.exec(sql"BEGIN") for migration in migrationsToDown: - info migration.name + info "Applying down script for " & migration.name if not migration.downPath.fileExists: pgConn.rollbackWithErr "Can not find DOWN file for " & migration.name & @@ -229,6 +229,7 @@ Usage: db_migrate [options] up [] db_migrate [options] down [] db_migrate [options] init + db_migrate [options] status db_migrate (-V | --version) db_migrate (-h | --help) @@ -249,7 +250,7 @@ Options: """ # 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 = fatal("db_migrate: " & msg) @@ -331,6 +332,21 @@ Options: except DbError: 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 let newResults = diffMigrations(pgConn, config)