كيفية استعادة موضوع محذوف باستخدام وحدة تحكم Rails

This is how the accidental deletion occurred:

cd /var/discourse
./launcher enter app
rails c
Topic.where(:id=><id>).destroy_all

The <id> I deleted was the wrong one and of course it just so happened to be a topic that a number of users were tuned into it. The important thing is I stopped, did not panic and did not execute another action after the accidental deletion occurred.

:stop_sign: Stop, :no_entry_sign: Do Not Panic and :no_entry_sign: Do Not Execute

How I recovered the accidentally deleted topic using the rails console:

destroyed_topic = _  
destroyed_topic.each do |destroyed_record|
  Topic.create(destroyed_record.attributes)
end

For future reference are there other ways could I have achieved this? If so, how?

صعب تحديد توقيت لهذا، لكن يجب أن يُحتفظ بـ destroy للحالات المؤكدة تمامًا ثلاث مرات. قم بنسخ احتياطي أولاً. لست متأكدًا مما إذا كان استعادتك هناك سيتسبب في انتشار الاستعادة ويعيد جميع السجلات التي تحتاجها.

بدلاً من ذلك:

Topic.find_by(id: <id>).trash!

للإستعادة:

Topic.with_deleted.where(id: <id>).recover!