From 125b2568bbeb12f050cfb76b94e84232a6cc8cd5 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Sat, 30 Oct 2021 13:59:34 +0200 Subject: Try out sqlite's user_version pragma I will not use it because the pragma does not appear in a .dump, therefore complicating backup and restore procedure --- src/database.nim | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/database.nim') diff --git a/src/database.nim b/src/database.nim index 37ef8b4..3657fab 100644 --- a/src/database.nim +++ b/src/database.nim @@ -1,4 +1,4 @@ -import std / [options, times] +import std / [options, strformat, times] import tiny_sqlite import uuids @@ -7,9 +7,6 @@ import dbUtils const migrations = [ """ - CREATE TABLE schema_version ( - version INTEGER NOT NULL - ); CREATE TABLE url ( id INTEGER PRIMARY KEY, token TEXT NOT NULL UNIQUE, @@ -26,7 +23,7 @@ const latestVersion = migrations.len proc Migrate*(db: DbConn): bool {.raises: [].} = var currentVersion: int try: - currentVersion = db.value("SELECT version FROM schema_version;").get().fromDbValue(int) + currentVersion = db.value("PRAGMA user_version").get().fromDbValue(int) except SqliteError: discard if currentVersion != latestVersion: @@ -34,9 +31,8 @@ proc Migrate*(db: DbConn): bool {.raises: [].} = db.exec("BEGIN") for v in currentVersion..