FIX: Staged users did not have a `UserEmail` record.
This commit is contained in:
parent
305b9b2da0
commit
6e74f726cf
|
@ -0,0 +1,28 @@
|
|||
class FixPrimaryEmailsForStagedUsers < ActiveRecord::Migration
|
||||
def up
|
||||
execute <<~SQL
|
||||
INSERT INTO user_emails (
|
||||
user_id,
|
||||
email,
|
||||
"primary",
|
||||
created_at,
|
||||
updated_at
|
||||
) SELECT
|
||||
users.id,
|
||||
email_tokens.email,
|
||||
'TRUE',
|
||||
users.created_at,
|
||||
users.updated_at
|
||||
FROM users
|
||||
LEFT JOIN user_emails ON user_emails.user_id = users.id
|
||||
LEFT JOIN email_tokens ON email_tokens.user_id = users.id
|
||||
WHERE staged
|
||||
AND NOT active
|
||||
AND user_emails.id IS NULL
|
||||
SQL
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue