discourse-topic-voting/db/migrate/20201003141123_remove_votes_of_deleted_users.rb

19 lines
432 B
Ruby

# frozen_string_literal: true
class RemoveVotesOfDeletedUsers < ActiveRecord::Migration[6.0]
def up
DB.exec <<~SQL
DELETE FROM discourse_voting_votes
WHERE user_id IN (
SELECT votes.user_id
FROM discourse_voting_votes votes
LEFT JOIN users ON users.id = votes.user_id
WHERE users.id IS NULL
)
SQL
end
def down
raise ActiveRecord::IrreversibleMigration
end
end