One of the Discourse sites that I operate is preparing to undergo a re-launch, and due to the large amount of inactivity on the forum, and the type of posts that have been made in the last year or so, I’d like to remove/delete all topics and start over fresh on the forums.
The easiest way is to use rails command line, ssh into your server and then
cd /var/discourse
./launcher enter app
rails c
Post.where("user_id > 0").where(post_number: 1).find_each do |post|
PostDestroyer.new(Discourse.system_user, post).destroy
putc "."
end
be sure to make a backup before running this destructive code.
Does running PostDestroyer.destroy actually remove the record from the database or does it merely mark the post as deleted, keeping it in the database?
There will be a lot of uses for a script that actually DELETES all the topics and posts, leaving everything (like site settings and users) there. Categories are yes/no.
Keep all site structure, (categories, groups, users, and settings), but wipe all threads, and PMS, and logs, basically to take a demo site that served as a sandbox, and transition it to a live site, similar to the OP, without having to setup a new instance and re-register all my users. But everything content wise, as well as logged actions all starts fresh.
Does this rake task posted above do this, or can the added reset logs as well be done, so all post data, and all log data is wiped fresh?
This is really useful, many thanks. It seems that this doesn’t remove any Custom Fields for the posts. In my case, I am trying to import posts, so the “import_id” custom fields remain, making the importer think the posts are still present, even though they are not. Any way to remove the custom field data as well?