How to delete EVERYTHING from my forum and just leave the users?

That’s the fastest and easiest way, from far.
Download your user list as @JammyDodger suggested, from /admin/users/list/active, download the CSV file, clean it up to keep only the email addresses, and do a bulk invite from your admin interface from a new Discourse installation. Your users will have to create an account again.

If you want to delete all data except some users, there is no easy way to do that and I can only think that trying could easily lead to a broken forum.

If you want to export most data of your users (their own settings and stuff), it will also be difficult and will require creating a ruby on rails script. Also, you could face issues that I didn’t think about. If you’re not sure how to do that, I’d suggest you stick to the first solution or post in marketplace if you have a budget.

1 Like

That’s true. But if you want to live dangerously, you can try this:

./launcher enter app
discourse backup
rails c
Topic.where("user_id > 1").destroy_all
Upload.where("user_id > 1").destroy_all
exit
exit

I think that deleting topics should delete posts, but you could also add a

 Post.where("user_id > 0").destroy_all

The > 1 will leave topics created by the first user. If you want to delete those as well, change it to > 0,which will leave topics created by @system. I think you’ll be very sorry if you delete those.

That makes a backup in case it destroys everything.

This is almost certainly a bad idea, but it’s what you asked for.

1 Like

Indeed! There’s the PostDestroyer class for that, which does a lot of necessary extra cleanup.

@xebiyen you can use this rake task to destroy all topics across all categories, but leave categories and users intact:

$ ./bin/rake destroy:topics_all_categories
4 Likes

Awesome, I didn’t know this rake task. Will it remove the “About” topics, which would be an unwanted side effect?

No, the method it uses leaves those alone by default, and the rake task does not change that default:

:rainbow:

1 Like

Thank you for confirming this. I wanted to be sure, because one or two of the recommended methods for other things listed on Administrative Bulk Operations had unwanted side effects the last time I used them.

I used one to move topics from one category to another but it moved the about topic along the regular topics. I might have used a rails script instead of the rake task though. I’m not sure. :thinking:

I also used the “move all topics with a specific tag to a single category” rake method, which didn’t populate properly some tags-related tables in the database.


edit: oh, it’s my Cake Day! If only the cake was real… But maybe it is though?

2 Likes

Thanks! I’d forgotten about that class and didn’t know about the rake task (or don’t remember forgetting it!)

2 Likes

what command do i use before this command?

@pfaffman @Canapin is his command @leonardo the best solution then?

You can try by yourself, but do a backup first.
Go to your discourse folder in command line.
Enter the container with ./launcher enter app.
Then write rake destroy:topics_all_categories.

See it in action (my test instance is very slow):

4 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.