discourse/db/post_migrate/20210324043327_delete_orpha...

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

20 lines
405 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class DeleteOrphanPostRevisions < ActiveRecord::Migration[6.0]
def up
sql = <<~SQL
DELETE FROM post_revisions
USING post_revisions pr
LEFT JOIN posts ON posts.id = pr.post_id
WHERE posts.id IS NULL
AND post_revisions.id = pr.id
SQL
execute(sql)
end
def down
raise ActiveRecord::IrreversibleMigration
end
end