Is it possible to delete posts from the database?

I apologize in advance if the question is too dummies.
I have access to the Discourse database (through the plugin).
Can I delete some of the posts (which I myself created in large quantities during testing) using the query?

delete from posts where id in (123, 567, ... etc)

Is it safe to perform such operations?

1 Like

If you are accessing the database through the Data Explorer plugin, that plugin only allows read-only queries. It is not possible to use it to write to the database.

It is possible to fully delete posts from the Rails console, but we don’t recommend doing that. Your best approach would be to use the Data Explorer plugin to find the posts you want to delete, and then use the tools availale on the Discourse user interface to remove the posts.

If for some reason this approach won’t work for you, let us know and we can give you details about deleting posts from the Rails console.

9 Likes

I am not expert in this engine, but i suppose that it is not safe, because like that you will only delete entry from posts table, and one post can have linked entries in other tables, and alot of meta information, linked to that post_id. And later on something might break. So you should use integrated tools for post deletion.

2 Likes

Thanks Nikolay.
I also think … But suddenly real experts on this application will come, and they will say - feel free to delete! )))

Except that no experts say it is OK:

  • It is not recommended.
  • It is not on the Discourse roadmap and there are no plans to add it.
  • It is not being developed because a permanent delete cannot be undone.
  • Nobody has paid to have this feature developed.

Nobody who has asked for it has developed this feature because it is either too difficult or is not worth the cost of developing it.

See this topic for examples of these points:

1 Like

I would not call myself an expert, but I have looked at, analyzed, and played with files and code a fair bit over the years.

I have seen enough to convince myself that on my own I am not knowledgeable enough to do more than experiment in localhost. What I have seen, and not seen, cause pause.

I have not ever seen a single “ON DELETE CASCADE”. I have seen a lot of “has_many”, “dependent:”, “Indexes” and “ensure_consistency” in a lot of model files. There is a job file https://github.com/discourse/discourse/blob/master/app/jobs/scheduled/ensure_db_consistency.rb

Personally, as much as I like Discourse, I would not expect them to deal with the consequences of actions that go outside of core safeguards. i.e. I often break my own code, but I take full responsibility when it happens. But that’s me. And there certainly can be some core code somewhere I’m not yet aware of.

1 Like

Also,

But that would be pointless in op’s case.

4 Likes