diff options
author | Julien Dessaux | 2021-10-30 13:59:34 +0200 |
---|---|---|
committer | Julien Dessaux | 2021-10-30 13:59:34 +0200 |
commit | 125b2568bbeb12f050cfb76b94e84232a6cc8cd5 (patch) | |
tree | b921c201cffca78e9de65af730f3672ce96017f2 /src/database.nim | |
parent | Changed for a better way to generate uuids (diff) | |
download | short-125b2568bbeb12f050cfb76b94e84232a6cc8cd5.tar.gz short-125b2568bbeb12f050cfb76b94e84232a6cc8cd5.tar.bz2 short-125b2568bbeb12f050cfb76b94e84232a6cc8cd5.zip |
Try out sqlite's user_version pragmauser_version_pragma
I will not use it because the pragma does not appear in a .dump,
therefore complicating backup and restore procedure
Diffstat (limited to 'src/database.nim')
-rw-r--r-- | src/database.nim | 12 |
1 files changed, 4 insertions, 8 deletions
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..<latestVersion: db.execScript(migrations[v]) - db.exec("DELETE FROM schema_version;") - db.exec("INSERT INTO schema_version (version) VALUES (?);", latestVersion) - db.exec("COMMIT;") + db.exec(&"PRAGMA user_version={latestVersion}") + db.exec("COMMIT") except: let msg = getCurrentExceptionMsg() echo msg |