DEV: follow up on bb8cdf9e, assume no dupe bounce_keys

We may have tons of emails in the email logs, assume none are duplicate
hunting for duplication can be very expensive.
This commit is contained in:
Sam Saffron 2019-05-03 10:51:58 +10:00
parent ce2c19457a
commit 413a54e7be

View File

@ -1,14 +1,5 @@
class AddBounceKeyIndexOnEmailLogs < ActiveRecord::Migration[5.2]
def change
execute <<~SQL
DELETE FROM email_logs l
WHERE bounce_key IS NOT NULL
AND id > (
SELECT MIN(id)
FROM email_logs l2
WHERE l2.bounce_key = l.bounce_key
)
SQL
add_index :email_logs, [:bounce_key], unique: true, where: 'bounce_key IS NOT NULL'
end
end