multica/server/migrations/018_comment_parent_cascade.down.sql
Naiyuan Qing 6cc8f7586a 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>
2026-03-28 22:04:35 +08:00

3 lines
199 B
SQL

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;