From 3e7c1db49e30ecc9443504ebbf92a04590acf9ea Mon Sep 17 00:00:00 2001
From: Charlie Darques <charlie.darques.etu@univ-lille.fr>
Date: Mon, 17 Mar 2025 11:10:33 +0100
Subject: [PATCH] correction sql

---
 sql/createTables.sql | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/sql/createTables.sql b/sql/createTables.sql
index fc1c896..098eae8 100644
--- a/sql/createTables.sql
+++ b/sql/createTables.sql
@@ -15,32 +15,46 @@ CREATE TABLE msg (
     threadID int,
     msg text,
     posted_at DATE,
-    CONSTRAINT fk_message FOREIGN KEY (userID_msg) REFERENCES userAccount(userID),
+    CONSTRAINT fk_message FOREIGN KEY (userID_msg) REFERENCES userAccount(userID)
+        ON DELETE CASCADE,
     CONSTRAINT pk_message PRIMARY KEY (msgID)
+
 );
 
 CREATE TABLE thread (
     threadID SERIAL,
     userID_thread int, 
     threadName VARCHAR(50),
-    CONSTRAINT fk_thread FOREIGN KEY (userID_thread) REFERENCES userAccount(userID),
-    CONSTRAINT pk_thread PRIMARY KEY (threadID) 
+    CONSTRAINT fk_thread FOREIGN KEY (userID_thread) REFERENCES userAccount(userID)
+    ON DELETE CASCADE,
+    CONSTRAINT pk_thread PRIMARY KEY (threadID)
+
 );
 
 CREATE TABLE reactions (
     userID_reactions int,
     msgID_reactions int,
     reaction boolean,
-    CONSTRAINT fk_reactions_user FOREIGN KEY (userID_reactions) REFERENCES userAccount(userID),
-    CONSTRAINT fk_reactions_message FOREIGN KEY (msgID_reactions) REFERENCES msg(msgID),
+    CONSTRAINT fk_reactions_user FOREIGN KEY (userID_reactions) REFERENCES userAccount(userID)
+    ON DELETE CASCADE
+    ,
+    CONSTRAINT fk_reactions_message FOREIGN KEY (msgID_reactions) REFERENCES msg(msgID)
+    ON DELETE CASCADE
+    ,
     CONSTRAINT pk_reactions PRIMARY KEY (userID_reactions, msgID_reactions)
+
 );
 
 CREATE TABLE follow (
     userID_follow int,
     threadID_follow int,
     followDate date,
-    CONSTRAINT fk_follow_user FOREIGN KEY (userID_follow) REFERENCES userAccount(userID),
-    CONSTRAINT fk_follow_thread FOREIGN KEY (threadID_follow) REFERENCES thread(threadID),
+    CONSTRAINT fk_follow_user FOREIGN KEY (userID_follow) REFERENCES userAccount(userID)
+    ON DELETE CASCADE
+    ,
+    CONSTRAINT fk_follow_thread FOREIGN KEY (threadID_follow) REFERENCES thread(threadID)
+    ON DELETE CASCADE
+    ,
     CONSTRAINT pk_follow PRIMARY KEY (userID_follow, threadID_follow)
+
 );
\ No newline at end of file
-- 
GitLab