import std / [options, strformat, times] import tiny_sqlite import uuids import dbUtils const migrations = [ """ CREATE TABLE url ( id INTEGER PRIMARY KEY, token TEXT NOT NULL UNIQUE, title TEXT NOT NULL, url TEXT, created DATE, expires DATE ); CREATE UNIQUE INDEX idx_url_token ON url(token); """ ] const latestVersion = migrations.len proc Migrate*(db: DbConn): bool {.raises: [].} = var currentVersion: int try: currentVersion = db.value("PRAGMA user_version").get().fromDbValue(int) except SqliteError: discard if currentVersion != latestVersion: try: db.exec("BEGIN") for v in currentVersion..