I’m not sure if it’s ideal, but I used this code to replace the user’s post content in deleted topics with "[deleted]"
. That way the existence of the posts was preserved, and it seemed safer than completely destroying them.
# backed-up first
deleted_topic_id = 1234
user_id = 5678
t = Topic.unscoped.find(deleted_topic_id)
ps = t.posts.select { |p| p.user_id == user_id }
# `ps.count` to check
ps.each do |p|
p.raw = '[deleted]'
p.save
end