migration to fix email_logs not attached to a user

This commit is contained in:
Régis Hanol 2016-02-01 19:37:10 +01:00
parent 12051f79a8
commit de58e58272

View file

@ -0,0 +1,16 @@
class FixEmailLogs < ActiveRecord::Migration
def up
execute <<-SQL
UPDATE email_logs
SET user_id = u.id
FROM email_logs el
LEFT JOIN users u ON u.email = el.to_address
WHERE email_logs.id = el.id
AND email_logs.user_id IS NULL
AND NOT email_logs.skipped
SQL
end
def down
end
end