discourse/db/migrate/20210308010745_delete_orphan_post_actions.rb
Krzysztof Kotlarek c5a116859d
FIX: delete post action from permanently deleted posts (#12309)
When Post is permanently deleted, we should delete correlated PostAction as well.
2021-03-18 15:22:41 +11:00

20 lines
387 B
Ruby

# 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