aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJulien Dessaux2021-11-01 15:55:27 +0100
committerJulien Dessaux2021-11-01 15:58:01 +0100
commit6c4142d421ae282d934ca1cfbbe4f71a09236cd3 (patch)
tree8b9b2503c8374b7abc2bbf3f7ce56baec2b2dd6f /src
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--src/short.nim8
1 files changed, 5 insertions, 3 deletions
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()