mirror of
https://github.com/System-End/hackatime.git
synced 2026-04-20 00:35:22 +00:00
Create 20250307224352_move_emails_to_email_addresses.rb
This commit is contained in:
parent
bea8372e30
commit
c013c3e0bf
1 changed files with 26 additions and 0 deletions
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
|
||||
Loading…
Add table
Reference in a new issue