aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2021-11-01 15:55:27 +0100
committerJulien Dessaux2021-11-01 15:58:01 +0100
commit6c4142d421ae282d934ca1cfbbe4f71a09236cd3 (patch)
tree8b9b2503c8374b7abc2bbf3f7ce56baec2b2dd6f
parentEnforce a more strict database schema (diff)
downloadshort-6c4142d421ae282d934ca1cfbbe4f71a09236cd3.tar.gz
short-6c4142d421ae282d934ca1cfbbe4f71a09236cd3.tar.bz2
short-6c4142d421ae282d934ca1cfbbe4f71a09236cd3.zip
Reworked the server to run database migrations only once on main process start
Diffstat (limited to '')
-rw-r--r--short.nimble2
-rw-r--r--src/short.nim8
2 files changed, 6 insertions, 4 deletions
diff --git a/short.nimble b/short.nimble
index 2834286..574c821 100644
--- a/short.nimble
+++ b/short.nimble
@@ -1,6 +1,6 @@
# Package
-version = "0.2.0"
+version = "0.3.0"
author = "Julien Dessaux"
description = "A simple, privacy friendly URL shortener"
license = "EUPL-1.2"
diff --git a/src/short.nim b/src/short.nim
index 9ab5f97..791c96a 100644
--- a/src/short.nim
+++ b/src/short.nim
@@ -38,9 +38,6 @@ var db {.threadvar.}: DbConn
proc initDB() {.raises: [SqliteError].} =
if not db.isOpen():
db = openDatabase("data/short.db")
- if not db.Migrate():
- echo "Failed to migrate database schema"
- quit 1
func renderIndex(): string {.raises: [].} =
var req: ShortUrl
@@ -143,4 +140,9 @@ routes:
resp code, htmlHeaders, content
when isMainModule:
+ initDb()
+ if not db.Migrate():
+ echo "Failed to migrate database schema"
+ quit 1
+ db.close()
runForever()