削除済み投稿を一括で完全に削除する?

In order to delete the old posts on our forum, I used this. It is the result of combining The proper way to completely delete hundred of topics via rails? and @RGJ’s suggestions.

I chose to do this in the end, as I really wanted to remove the data from the database to protect the privacy of users. Rewriting the text to “This post has been deleted” still leaves the edit history intact and relatively easily accessible, so not good enough.

As we had 20,000 topics to destroy, it took a while!

Topic.with_deleted.where("deleted_at < '2021-08-28'").limit(1000).destroy_all

As this left a lot of orphaned posts, I had to follow it up with:

Post.where('topic_id not in (select id from topics)').limit(1000).destroy_all
「いいね!」 4