How to delete thousands of Private Messages?

Well, I think that this will do what you asked. It will delete any private messages that were not created by a system user or discobot. It will still delete any other private messages, including those from admins.

It’s not tested. I’m not saying that it’s a good idea. I won’t promise that it won’t do something bad.

cd /var/discourse
discourse backup
./launcher enter app
rails s
Topic.where(archetype: 'private_message').where("user_id > 0").destroy_all
exit
discourse enable_restore
discourse restore

If something bad does not happen, you can omit the last two steps. If something bad does happen, you’ll want to copy/paste the most recent backup printed by the discourse restore command to restore the backup.

3 Likes