Compare commits
No commits in common. "main" and "0.3.0" have entirely different histories.
@ -1,7 +1,7 @@
|
||||
# Package
|
||||
|
||||
bin = @["db_migrate"]
|
||||
version = "0.3.2"
|
||||
version = "0.3.0"
|
||||
author = "Jonathan Bernard"
|
||||
description = "Simple tool to handle database migrations."
|
||||
license = "BSD"
|
||||
@ -9,4 +9,4 @@ srcDir = "src/main/nim"
|
||||
|
||||
# Dependencies
|
||||
|
||||
requires: @["nim >= 2.0.0", "docopt >= 0.1.0", "db_connector"]
|
||||
requires: @["nim >= 1.4.0", "docopt >= 0.1.0"]
|
||||
|
@ -3,10 +3,8 @@
|
||||
##
|
||||
## Simple tool to manage database migrations.
|
||||
|
||||
import std/[algorithm, json, logging, os, sequtils, sets, strutils, tables,
|
||||
times]
|
||||
import db_connector/db_postgres
|
||||
import docopt
|
||||
import algorithm, db_postgres, docopt, json, logging, os, sequtils, sets,
|
||||
strutils, tables, times
|
||||
|
||||
type
|
||||
DbMigrateConfig* = object
|
||||
@ -91,9 +89,6 @@ proc diffMigrations*(
|
||||
run: seq[string],
|
||||
notRun, missing: seq[MigrationEntry] ] =
|
||||
|
||||
debug "diffMigrations: inspecting database and configured directories " &
|
||||
"for migrations"
|
||||
|
||||
# Query the database to find out what migrations have been run.
|
||||
var migrationsRun = initHashSet[string]()
|
||||
|
||||
@ -103,9 +98,7 @@ proc diffMigrations*(
|
||||
# Inspect the filesystem to see what migrations are available.
|
||||
var migrationsAvailable = newTable[string, MigrationEntry]()
|
||||
for sqlDir in config.sqlDirs:
|
||||
debug "Looking in " & sqlDir
|
||||
for filePath in walkFiles(joinPath(sqlDir, "*.sql")):
|
||||
debug "Saw migration file: " & filePath
|
||||
var migrationName = filePath.extractFilename
|
||||
migrationName.removeSuffix("-up.sql")
|
||||
migrationName.removeSuffix("-down.sql")
|
||||
@ -132,18 +125,11 @@ proc diffMigrations*(
|
||||
missingMigrations.add(migrationsNotRun)
|
||||
migrationsNotRun = newSeq[MigrationEntry]()
|
||||
|
||||
result = (available: migrationsAvailable,
|
||||
return (available: migrationsAvailable,
|
||||
run: toSeq(migrationsRun.items).sorted(system.cmp),
|
||||
notRun: migrationsNotRun,
|
||||
missing: missingMigrations)
|
||||
|
||||
debug "diffMigration: Results" &
|
||||
"\n\tavailable: " & $toSeq(result[0].keys) &
|
||||
"\n\trun: " & $result[1] &
|
||||
"\n\tnotRun: " & $(result[2].mapIt(it.name)) &
|
||||
"\n\tmissing: " & $(result[3].mapIt(it.name))
|
||||
|
||||
|
||||
proc readStatements*(filename: string): seq[SqlQuery] =
|
||||
result = @[]
|
||||
var stmt: string = ""
|
||||
@ -249,7 +235,7 @@ Options:
|
||||
"""
|
||||
|
||||
# Parse arguments
|
||||
let args = docopt(doc, version = "db-migrate (Nim) 0.3.2\nhttps://git.jdb-software.com/jdb/db-migrate")
|
||||
let args = docopt(doc, version = "db-migrate (Nim) 0.3.0\nhttps://git.jdb-software.com/jdb/db-migrate")
|
||||
|
||||
let exitErr = proc(msg: string): void =
|
||||
fatal("db_migrate: " & msg)
|
||||
|
Loading…
x
Reference in New Issue
Block a user