A platform for community discussion. Free, open, simple.
FIX: delete post action from permanently deleted posts (#12309)
Krzysztof Kotlarekc5a116859dbf
diff --git a/app/models/post.rb b/app/models/post.rbindex 5afec60316f..7bdc472599b 100644--- a/app/models/post.rb+++ b/app/models/post.rb@@ -34,7 +34,7 @@ class Post < ActiveRecord::Basehas_many :post_replieshas_many :replies, through: :post_replies- has_many :post_actions+ has_many :post_actions, dependent: :destroyhas_many :topic_linkshas_many :group_mentions, dependent: :destroydiff --git a/db/migrate/20210308010745_delete_orphan_post_actions.rb b/db/migrate/20210308010745_delete_orphan_post_actions.rbnew file mode 100644index 00000000000..4abea24789e--- /dev/null+++ b/db/migrate/20210308010745_delete_orphan_post_actions.rb@@ -0,0 +1,19 @@+# frozen_string_literal: true++class DeleteOrphanPostActions < ActiveRecord::Migration[6.0]+ def up+ sql = <<~SQL+ DELETE FROM post_actions+ USING post_actions pa+ LEFT JOIN posts ON posts.id = pa.post_id+ WHERE posts.id IS NULL+ AND post_actions.id = pa.id+ SQL++ execute(sql)+ end++ def down+ raise ActiveRecord::IrreversibleMigration+ end+end