From 6cc8f7586af002023e93f132fa5ddf28ff1a3b9e Mon Sep 17 00:00:00 2001 From: Naiyuan Qing <145280634+NevilleQingNY@users.noreply.github.com> Date: Sat, 28 Mar 2026 22:04:35 +0800 Subject: [PATCH] fix(comments): cascade delete replies in DB when parent comment is deleted Change parent_id FK from ON DELETE SET NULL to ON DELETE CASCADE. Deleting a parent comment now deletes all its replies at the DB level. Co-Authored-By: Claude Opus 4.6 (1M context) --- server/migrations/018_comment_parent_cascade.down.sql | 3 +++ server/migrations/018_comment_parent_cascade.up.sql | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 server/migrations/018_comment_parent_cascade.down.sql create mode 100644 server/migrations/018_comment_parent_cascade.up.sql diff --git a/server/migrations/018_comment_parent_cascade.down.sql b/server/migrations/018_comment_parent_cascade.down.sql new file mode 100644 index 00000000..ef56c144 --- /dev/null +++ b/server/migrations/018_comment_parent_cascade.down.sql @@ -0,0 +1,3 @@ +ALTER TABLE comment DROP CONSTRAINT IF EXISTS comment_parent_id_fkey; +ALTER TABLE comment ADD CONSTRAINT comment_parent_id_fkey + FOREIGN KEY (parent_id) REFERENCES comment(id) ON DELETE SET NULL; diff --git a/server/migrations/018_comment_parent_cascade.up.sql b/server/migrations/018_comment_parent_cascade.up.sql new file mode 100644 index 00000000..986e6863 --- /dev/null +++ b/server/migrations/018_comment_parent_cascade.up.sql @@ -0,0 +1,3 @@ +ALTER TABLE comment DROP CONSTRAINT IF EXISTS comment_parent_id_fkey; +ALTER TABLE comment ADD CONSTRAINT comment_parent_id_fkey + FOREIGN KEY (parent_id) REFERENCES comment(id) ON DELETE CASCADE;