summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordan <[email protected]>2024-04-28 12:16:04 -0400
committerdan <[email protected]>2024-04-28 12:16:04 -0400
commitdb31f4f8774f8cfc2cb06fca37f1ab10dda208bc (patch)
tree86c57382680e2fa0502ec9fb6ece5e3557c2a43c
parent43258a695765374968540f22319e8cd62da45297 (diff)
download54-db31f4f8774f8cfc2cb06fca37f1ab10dda208bc.tar.gz
54-db31f4f8774f8cfc2cb06fca37f1ab10dda208bc.tar.bz2
54-db31f4f8774f8cfc2cb06fca37f1ab10dda208bc.zip
fix: always run sql to create tables, but as "IF NOT EXISTS"
-rw-r--r--main.scm29
1 files changed, 16 insertions, 13 deletions
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)