From 21f01fed02aec29b6730bde65cbf0c42a699bd69 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Thu, 23 Dec 2021 08:56:50 +0100 Subject: [PATCH] Use an INSERT INTO ... SELECT to move profile data and drop the old columns --- db/migrate/20211219153054_create_profiles.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/db/migrate/20211219153054_create_profiles.rb b/db/migrate/20211219153054_create_profiles.rb index 199a63f3..d6480af9 100644 --- a/db/migrate/20211219153054_create_profiles.rb +++ b/db/migrate/20211219153054_create_profiles.rb @@ -11,14 +11,14 @@ class CreateProfiles < ActiveRecord::Migration[5.2] t.timestamps end - User.find_each do |user| - Profile.create!( - user_id: user.id, - display_name: user.display_name, - description: user.bio, - location: user.location, - website: user.website, - ) + transaction do + 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;' + + remove_column :users, :display_name + remove_column :users, :bio + remove_column :users, :location + remove_column :users, :website + remove_column :users, :motivation_header end end end