Is there a way to wipe out an entire category of topics?


(Tobias Eigen) #1

I have been doing some testing of importing content and it didn’t go as hoped - so I’d like to delete all the content and try again. Is there a way to wipe out an entire category of topics and posts?


(Kane York) #2

Probably something like this in the rails console?

c = Category.find(5)
#<Category id: 5, name: meta, ...>
Topic.where(category: c).delete

(Sam Saffron) #3

A bit trickier that that, I am pretty sure it will not cascade.


(Kane York) #4

Yeah, I was wondering about that. What does the admin “delete topic” button do? Maybe the script could call that code for every topic in the category instead.


(Paul Apostolos) #5

What about this using the api…

Get a list of all users.

Loop through all users

Call PUT /admin/users/{id}/delete_all_posts

Followed by DELETE /admin/users/{id}.json

That should be scriptable in any language


(Kane York) #6

Oh, didn’t see that part…

@tobiaseigen you could also cd /var/docker followed by rm -rf shared/postgres_* to wipe all the data from a Docker install.


(Michael Brown) #7

Next time, you can probably streamline the process by taking a backup, testing import, then reverting by restoring the backup.

Of course the ‘backup’ could be the shared folder or a Discourse backup.


(Tobias Eigen) #8

Yes, but that would nuke all the other settings and users as well, right? I just want to nuke the content in those categories.


(Tobias Eigen) #9

Now you tell me. :wink: Actually, I realized that myself already and for next time will take snapshot backups before doing crazy stuff…