Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/api/src/main/resources/db/migration/V1__init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ CREATE TABLE posts (
author_id UUID NOT NULL,
text VARCHAR(280) NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT fk_parent_id FOREIGN KEY (parent_id) REFERENCES posts(id),
CONSTRAINT fk_conversation_id FOREIGN KEY (conversation_id) REFERENCES posts(id),
CONSTRAINT fk_author_id FOREIGN KEY (author_id) REFERENCES profiles(id)
CONSTRAINT fk_parent_id FOREIGN KEY (parent_id) REFERENCES posts(id) ON DELETE CASCADE,
CONSTRAINT fk_conversation_id FOREIGN KEY (conversation_id) REFERENCES posts(id) ON DELETE CASCADE,
CONSTRAINT fk_author_id FOREIGN KEY (author_id) REFERENCES profiles(id) ON DELETE CASCADE
);

CREATE TABLE post_likes (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,4 +555,17 @@ void PostRepository_FindPostsMentioningProfileId_ContainsOnlyPostsMentioningUser
}
}

@Test
void PostRepository_Delete_CascadeDeletesRelatedPosts() {
Post root = createPost(null, self.getId(), "root.");
Post replyToRoot = createPost(root.getId(), self.getId(), "reply to root.");
Post replyToReply = createPost(replyToRoot.getId(), self.getId(), "reply to reply.");

postRepository.delete(root);

assertFalse(postRepository.existsById(root.getId()));
assertFalse(postRepository.existsById(replyToRoot.getId()));
assertFalse(postRepository.existsById(replyToReply.getId()));
}

}
Loading