Use an INSERT INTO ... SELECT to move profile data and drop the old columns
This commit is contained in:
parent
65fa3ff018
commit
21f01fed02
|
@ -11,14 +11,14 @@ class CreateProfiles < ActiveRecord::Migration[5.2]
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
|
|
||||||
User.find_each do |user|
|
transaction do
|
||||||
Profile.create!(
|
execute 'INSERT INTO profiles (user_id, display_name, description, location, website, motivation_header, created_at, updated_at) SELECT users.id as user_id, users.display_name, users.bio as description, users.location, users.website, users.motivation_header, users.created_at, users.updated_at FROM users;'
|
||||||
user_id: user.id,
|
|
||||||
display_name: user.display_name,
|
remove_column :users, :display_name
|
||||||
description: user.bio,
|
remove_column :users, :bio
|
||||||
location: user.location,
|
remove_column :users, :location
|
||||||
website: user.website,
|
remove_column :users, :website
|
||||||
)
|
remove_column :users, :motivation_header
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue