mirror of
https://github.com/SrIzan10/hc-harbor.git
synced 2026-05-01 10:45:21 +00:00
Create 20250307224352_move_emails_to_email_addresses.rb
This commit is contained in:
26
db/migrate/20250307224352_move_emails_to_email_addresses.rb
Normal file
26
db/migrate/20250307224352_move_emails_to_email_addresses.rb
Normal 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
|
||||
Reference in New Issue
Block a user