class AddUserInfoToUserActions < ActiveRecord::Migration[5.2]
  def change
    add_column :user_actions, :login, :string
    add_column :user_actions, :phone, :string
    add_column :user_actions, :email, :string
    add_column :user_actions, :memo, :text

    UserAction.find_in_batches(batch_size: 1000) do |sw|
      Parallel.each(sw, in_threads: 1) do |user_action|
        if user_action.user.present?
          user_action.login = user_action.user&.login
          user_action.email = user_action.user&.mail
          user_action.phone = user_action.user&.phone
          user_action.save
        end
      end
    end
  end

end
