Update for Nim 1.4.x+
This commit is contained in:
parent
daf3a8dad0
commit
6837e5448b
@ -1,7 +1,7 @@
|
|||||||
# Package
|
# Package
|
||||||
|
|
||||||
bin = @["db_migrate"]
|
bin = @["db_migrate"]
|
||||||
version = "0.2.7"
|
version = "0.2.8"
|
||||||
author = "Jonathan Bernard"
|
author = "Jonathan Bernard"
|
||||||
description = "Simple tool to handle database migrations."
|
description = "Simple tool to handle database migrations."
|
||||||
license = "BSD"
|
license = "BSD"
|
||||||
@ -9,5 +9,4 @@ srcDir = "src/main/nim"
|
|||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
|
||||||
requires: @["nim >= 0.13.0", "docopt >= 0.1.0"]
|
requires: @["nim >= 1.4.0", "docopt >= 0.1.0"]
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
##
|
##
|
||||||
## Simple tool to manage database migrations.
|
## Simple tool to manage database migrations.
|
||||||
|
|
||||||
import algorithm, json, times, os, strutils, docopt, db_postgres, sets,
|
import algorithm, db_postgres, docopt, json, logging, os, sequtils, sets,
|
||||||
sequtils, logging
|
strutils, times
|
||||||
|
|
||||||
type
|
type
|
||||||
DbMigrateConfig* = tuple[ driver, sqlDir, connectionString: string, logLevel: Level ]
|
DbMigrateConfig* = tuple[ driver, sqlDir, connectionString: string, logLevel: Level ]
|
||||||
@ -55,7 +55,7 @@ proc loadConfig*(filename: string): DbMigrateConfig =
|
|||||||
|
|
||||||
proc createMigration*(config: DbMigrateConfig, migrationName: string): seq[string] =
|
proc createMigration*(config: DbMigrateConfig, migrationName: string): seq[string] =
|
||||||
## Create a new set of database migration files.
|
## Create a new set of database migration files.
|
||||||
let timestamp = getTime().getLocalTime().format("yyyyMMddHHmmss")
|
let timestamp = now().format("yyyyMMddHHmmss")
|
||||||
let filenamePrefix = timestamp & "-" & migrationName
|
let filenamePrefix = timestamp & "-" & migrationName
|
||||||
|
|
||||||
let upFilename = joinPath(config.sqlDir, filenamePrefix & "-up.sql")
|
let upFilename = joinPath(config.sqlDir, filenamePrefix & "-up.sql")
|
||||||
@ -78,13 +78,13 @@ proc diffMigrations*(pgConn: DbConn, config: DbMigrateConfig):
|
|||||||
tuple[ run, notRun, missing: seq[string] ] =
|
tuple[ run, notRun, missing: seq[string] ] =
|
||||||
|
|
||||||
# Query the database to find out what migrations have been run.
|
# Query the database to find out what migrations have been run.
|
||||||
var migrationsRun = initSet[string]()
|
var migrationsRun = initHashSet[string]()
|
||||||
|
|
||||||
for row in pgConn.fastRows(sql"SELECT * FROM migrations ORDER BY name", @[]):
|
for row in pgConn.fastRows(sql"SELECT * FROM migrations ORDER BY name", @[]):
|
||||||
migrationsRun.incl(row[1])
|
migrationsRun.incl(row[1])
|
||||||
|
|
||||||
# Inspect the filesystem to see what migrations are available.
|
# Inspect the filesystem to see what migrations are available.
|
||||||
var migrationsAvailable = initSet[string]()
|
var migrationsAvailable = initHashSet[string]()
|
||||||
for filePath in walkFiles(joinPath(config.sqlDir, "*.sql")):
|
for filePath in walkFiles(joinPath(config.sqlDir, "*.sql")):
|
||||||
var migrationName = filePath.extractFilename
|
var migrationName = filePath.extractFilename
|
||||||
migrationName.removeSuffix("-up.sql")
|
migrationName.removeSuffix("-up.sql")
|
||||||
@ -215,7 +215,7 @@ Options:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Parse arguments
|
# Parse arguments
|
||||||
let args = docopt(doc, version = "db-migrate (Nim) 0.2.7\nhttps://git.jdb-labs.com/jdb/db-migrate")
|
let args = docopt(doc, version = "db-migrate (Nim) 0.2.8\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)
|
||||||
@ -243,7 +243,7 @@ Options:
|
|||||||
else: logging.setLogFilter(config.logLevel)
|
else: logging.setLogFilter(config.logLevel)
|
||||||
|
|
||||||
# Check for migrations directory
|
# Check for migrations directory
|
||||||
if not existsDir config.sqlDir:
|
if not dirExists config.sqlDir:
|
||||||
try:
|
try:
|
||||||
warn "SQL directory '" & config.sqlDir &
|
warn "SQL directory '" & config.sqlDir &
|
||||||
"' does not exist and will be created."
|
"' does not exist and will be created."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user