Skip to content

Support persistence of deleted posts#363

Merged
allouis merged 3 commits intomainfrom
ap-812-storage-of-deleted-posts
Mar 4, 2025
Merged

Support persistence of deleted posts#363
allouis merged 3 commits intomainfrom
ap-812-storage-of-deleted-posts

Conversation

@allouis
Copy link
Collaborator

@allouis allouis commented 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 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.

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.
@allouis allouis force-pushed the ap-812-storage-of-deleted-posts branch from 3d5dc7d to cd8e1d0 Compare March 4, 2025 10:25
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 });
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@allouis allouis merged commit 0ea2d1b into main Mar 4, 2025
3 checks passed
@allouis allouis deleted the ap-812-storage-of-deleted-posts branch March 4, 2025 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants