diff options
-rw-r--r-- | main.scm | 29 |
1 files changed, 16 insertions, 13 deletions
@@ -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) |