From 4ed29fd24047cd613e040c187c14b2cde5422038 Mon Sep 17 00:00:00 2001 From: Francesco Gazzetta Date: Wed, 29 Nov 2023 15:15:05 +0100 Subject: [PATCH] Misc SQL improvements --- app/Main.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 0a0da99..476e72f 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -74,10 +74,10 @@ main = SQL.withConnection "gemini-textboard.db" $ \conn -> do createTables :: SQL.Connection -> IO () createTables conn = do SQL.execute_ conn $ "CREATE TABLE IF NOT EXISTS posts " <> - "(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, " <> + -- NOTE: AUTOINCREMENT here is important: it prevents the reuse of deleted ids + "(id INTEGER PRIMARY KEY AUTOINCREMENT, " <> "parent INTEGER, content TEXT NOT NULL, author TEXT, time TEXT NOT NULL, " <> - "FOREIGN KEY(parent) REFERENCES posts(id))" - SQL.execute_ conn "CREATE UNIQUE INDEX IF NOT EXISTS post_id_index ON posts (id)" + "FOREIGN KEY(parent) REFERENCES posts(id) ON DELETE CASCADE)" SQL.execute_ conn "CREATE INDEX IF NOT EXISTS post_parent_index ON posts (parent)" SQL.execute_ conn "CREATE INDEX IF NOT EXISTS post_time_index ON posts (time)" -- 2.45.2