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) <noreply@anthropic.com>
This commit is contained in:
Naiyuan Qing 2026-03-28 22:04:35 +08:00
parent 8a9ae0102d
commit 6cc8f7586a
2 changed files with 6 additions and 0 deletions

View file

@ -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;

View file

@ -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;