Create 20250307224352_move_emails_to_email_addresses.rb

This commit is contained in:
Max Wofford 2025-03-07 18:11:37 -05:00
parent bea8372e30
commit c013c3e0bf

View file

@ -0,0 +1,26 @@
class MoveEmailsToEmailAddresses < ActiveRecord::Migration[8.0]
def up
execute <<-SQL
INSERT INTO email_addresses (email, user_id, created_at, updated_at)
SELECT email, id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP
FROM users
WHERE email IS NOT NULL
SQL
remove_column :users, :email
end
def down
add_column :users, :email, :string
execute <<-SQL
UPDATE users
SET email = (
SELECT email
FROM email_addresses
WHERE email_addresses.user_id = users.id
LIMIT 1
)
SQL
end
end