Using topic.destroy(id) to delete illegal content

AI-generated summary

Here is a summary of the discussion on using topic.destroy(id) to delete illegal content:

vikaskedia wanted to permanently delete a topic for legal reasons by running topic.destroy(id) in the Rails console. This deleted the topic but the category still counted it.

Mittineague suggested also deleting related rows in other tables that reference the topic id, though noted this is not officially supported and simpler to use the UI.

vikaskedia clarified they were not directly editing the database and were relying on Rails to handle dependencies. They linked to a post indicating this may delete dependent objects.

Mittineague shared another relevant link.

vikaskedia noted improvements since that old 2014 post. They explained someone posted questionable content so a soft delete doesn’t work. They understand not having delete in the UI but topic.destroy seems to call PostDestroyer to handle dependencies.

My goal was to delete a topic from the DB due to legal reasons.

so I ran the command:

root@he-ps09-superstars:/var/www/discourse# echo “Topic.destroy(id)” | rails c

The topic was deleted :+1:

The category still thinks there is 1 topic and I cannot delete the category.

What other tables cross index the topic id?
Did you delete those rows as well?
What other tables cross index fields in those other tables?
Did you delete those rows?
rinse - repeat - until all are deleted.

IMHO it is much safer and a lot simpler to “delete” a topic using the UI than to delete it from the database.

AFAIK there is no “on delete cascade” code in Core and deleting fields from tables is not a supported practice, and hence not a Bug.

I am not touching postgres. I am letting the code do its work

As per @sam at: https://meta.discourse.org/t/how-to-permanent-delete-a-topic-from-database-with-his-posts/15073/2?u=vikaskedia this may nuke dependent objects.

Yes, but
https://meta.discourse.org/t/how-to-permanent-delete-a-topic-from-database-with-his-posts/15073/4?u=mittineague

hahaha !! that post was written in 2014 i think there might have been improvments after that ..

Someone posted questionable content .. hence just a soft delete just does not work.

Though I completely get @codinghorror point that there should not be hard delete in the UI. Since that creates a lot of possibilities for mischief.

Here is the code for topic.destroy discourse/app/controllers/topics_controller.rb at 5f19ad95074329bea3328a796f061de79db9c227 · discourse/discourse · GitHub this does seem to call PostDestroyer