debian-mirror-gitlab/db/post_migrate/20200819202048_remove_orphaned_emails.rb
2020-11-24 15:15:51 +05:30

20 lines
367 B
Ruby

# frozen_string_literal: true
class RemoveOrphanedEmails < ActiveRecord::Migration[6.0]
DOWNTIME = false
def up
execute <<~SQL
DELETE FROM emails
WHERE not exists (
SELECT 1 FROM users WHERE users.id = emails.user_id
);
SQL
execute 'DELETE FROM emails WHERE user_id IS NULL;'
end
def down
# no-op
end
end