discourse/db/migrate/20230119091939_drop_orphaned_reviewable_flagged_posts.rb
Selase Krakani bd2ca8d617
DEV: Promote historic post_deploy migrations (#25329)
This commit promotes all post_deploy migrations which existed in Discourse v3.1.0 (timestamp <= 20230405121454)
2024-01-19 13:59:20 +00:00

18 lines
462 B
Ruby

# frozen_string_literal: true
class DropOrphanedReviewableFlaggedPosts < ActiveRecord::Migration[7.0]
def up
DB.exec(<<~SQL)
DELETE FROM reviewables
WHERE reviewables.type = 'ReviewableFlaggedPost'
AND reviewables.status = 0
AND reviewables.target_type = 'Post'
AND NOT EXISTS(SELECT 1 FROM posts WHERE posts.id = reviewables.target_id)
SQL
end
def down
raise ActiveRecord::IrreversibleMigration
end
end