From db31f4f8774f8cfc2cb06fca37f1ab10dda208bc Mon Sep 17 00:00:00 2001 From: dan Date: Sun, 28 Apr 2024 12:16:04 -0400 Subject: fix: always run sql to create tables, but as "IF NOT EXISTS" --- main.scm | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'main.scm') diff --git a/main.scm b/main.scm index f163267..da7653a 100644 --- a/main.scm +++ b/main.scm @@ -15,19 +15,22 @@ (define db (open-database (or (get-environment-variable "DB_FILE") "/tmp/54itter.db"))) -(when (zero? (first-result db "SELECT count(*) FROM sqlite_master WHERE type='table' AND name='posts'")) - (execute db "CREATE TABLE posts ( - id TEXT PRIMARY KEY, - user_id TEXT, - content TEXT, - created_at DATETIME default current_timestamp, - parent_id TEXT - )") - (execute db "CREATE TABLE flush_votes ( - user_id TEXT PRIMARY KEY, - created_at DATETIME default current_timestamp - )") - ) +(execute db "CREATE TABLE IF NOT EXISTS posts ( + id TEXT PRIMARY KEY, + user_id TEXT, + content TEXT, + created_at DATETIME default current_timestamp, + parent_id TEXT + )") +(execute db "CREATE TABLE IF NOT EXISTS flush_votes ( + user_id TEXT PRIMARY KEY, + created_at DATETIME default current_timestamp + )") +(execute db "CREATE TABLE IF NOT EXISTS users ( + user_id TEXT PRIMARY KEY, + pw_hash TEXT, + created_at DATETIME default current_timestamp + )") (define (gen-id) (+ (pseudo-random-integer 65536) -- cgit v1.2.3