Merged
Conversation
mike182uk
reviewed
Mar 4, 2025
ref https://linear.app/ghost/issue/AP-812 We need to mark deleted posts as deleted in the DB, as well as emit a PostDeletedEvent so that other systems can react to it, for example removing the post from the feed after a deletion. Newly created posts that are immediately deleted are not a use-case we have and it's not clear on how that should work, this implementation simply does not persist them for now, but we can change that in future if we need to support this. When a post is deleted, the only column we write to is the deleted_at column, this ensures that the content is still available for audit, debug, undoing etc... We also update the reply count of its parent, if it exists. We also have to add a new check that the Post author Account has an id property, I would like to move this constraint to the entity layer, but that is outside the scope of this PR. Right now this check still happens, but it is implicit at the DB level with a foreign key constraint on the column - this just makes it explicit so that 1) we are all aware of it and 2) TypeScript doesn't complain about referencing author.id when instantiating the PostDeletedEvent.
3d5dc7d to
cd8e1d0
Compare
mike182uk
approved these changes
Mar 4, 2025
Comment on lines
+411
to
+417
| if (post.inReplyTo) { | ||
| await transaction('posts') | ||
| .update({ | ||
| reply_count: this.db.raw('reply_count - 1'), | ||
| }) | ||
| .where({ id: post.inReplyTo }); | ||
| } |
Member
There was a problem hiding this comment.
Think we need to cover this in the existing test or a new test
| if (existingRow && existingRow.deleted_at === null) { | ||
| await transaction('posts') | ||
| .update({ | ||
| deleted_at: transaction.raw('CURRENT_TIMESTAMP'), |
Member
There was a problem hiding this comment.
Based on what was discussed in Slack, do we want to use UTC_TIMESTAMP here now, or do we want to do a big bang change later?
Collaborator
Author
There was a problem hiding this comment.
Yeah so I wanted to do a big bang change so that we can do any migrations if necessary and all the current data is consistent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ref https://linear.app/ghost/issue/AP-812
We need to mark deleted posts as deleted in the DB, as well as emit a PostDeletedEvent so that other systems can react to it, for example removing the post from the feed after a deletion.
Newly created posts that are immediately deleted are not a use-case we have and it's not clear on how that should work, this implementation simply does not persist them for now, but we can change that in future if we need to support this.
When a post is deleted, the only column we write to is the deleted_at column, this ensures that the content is still available for audit, debug, undoing etc...
We also have to add a new check that the Post author Account has an id property, I would like to move this constraint to the entity layer, but that is outside the scope of this PR. Right now this check still happens, but it is implicit at the DB level with a foreign key constraint on the column - this just makes it explicit so that 1) we are all aware of it and 2) TypeScript doesn't complain about referencing author.id when instantiating the PostDeletedEvent.