From 038b83e5306d545471eb5ab1f5dbb4bfa0cac4b3 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Fri, 22 Mar 2024 23:38:08 +0100 Subject: [PATCH] Cascading --- server/migrations/0002_posts_table.sql | 2 +- server/migrations/0005_engagements_table.sql | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/migrations/0002_posts_table.sql b/server/migrations/0002_posts_table.sql index 2ab5280..59edafa 100644 --- a/server/migrations/0002_posts_table.sql +++ b/server/migrations/0002_posts_table.sql @@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS posts ( content TEXT NOT NULL, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - FOREIGN KEY (user_id) REFERENCES users (id) + FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE ); -- Create a function to set created_at and updated_at on INSERT diff --git a/server/migrations/0005_engagements_table.sql b/server/migrations/0005_engagements_table.sql index 9b65696..3e6960f 100644 --- a/server/migrations/0005_engagements_table.sql +++ b/server/migrations/0005_engagements_table.sql @@ -1,7 +1,7 @@ CREATE TABLE IF NOT EXISTS engagements ( user_id BIGINT NOT NULL, post_id BIGINT NOT NULL, - FOREIGN KEY (user_id) REFERENCES users (id), - FOREIGN KEY (post_id) REFERENCES posts (id), + FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE, + FOREIGN KEY (post_id) REFERENCES posts (id) ON DELETE CASCADE, PRIMARY KEY (user_id, post_id) ); \ No newline at end of file