From 631535dc89c960261a8ab87d80c9f5b6c28c4fd3 Mon Sep 17 00:00:00 2001 From: andreas-unleash Date: Fri, 24 Feb 2023 13:19:43 +0200 Subject: [PATCH] fix: add on delete cascade to notifications and userNotifications tables (#3192) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## About the changes Closes # ### Important files ## Discussion points Signed-off-by: andreas-unleash --- .../20230222154915-create-notiications-table.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/migrations/20230222154915-create-notiications-table.js b/src/migrations/20230222154915-create-notiications-table.js index c7a7130b7b..6207f47254 100644 --- a/src/migrations/20230222154915-create-notiications-table.js +++ b/src/migrations/20230222154915-create-notiications-table.js @@ -5,15 +5,15 @@ exports.up = function (db, cb) { ` CREATE TABLE IF NOT EXISTS notifications ( id SERIAL PRIMARY KEY, - event_id INTEGER NOT NULL REFERENCES events (id), - created_by INTEGER NOT NULL REFERENCES users (id), + event_id INTEGER NOT NULL REFERENCES events (id) ON DELETE CASCADE, + created_by INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE, created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now() ); CREATE TABLE if not exists user_notifications ( - notification_id INTEGER NOT NULL REFERENCES notifications (id), - user_id INTEGER NOT NULL REFERENCES users (id), + notification_id INTEGER NOT NULL REFERENCES notifications (id) ON DELETE CASCADE, + user_id INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE, read_at TIMESTAMP WITH TIME ZONE, PRIMARY KEY (notification_id, user_id) );