You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
15 lines
618 B
15 lines
618 B
class TransferPartnerManagerData < ActiveRecord::Migration[5.2]
|
|
def change
|
|
ActiveRecord::Base.transaction do
|
|
Partner.find_each do |partner|
|
|
manager_group = partner.partner_manager_groups.find_or_create_by(name: '管理者', admin: true)
|
|
|
|
user_ids = User.where(partner_id: partner.id).pluck(:id)
|
|
PartnerManager.bulk_insert(*%i[user_id partner_id partner_manager_group_id created_at updated_at]) do |worker|
|
|
user_ids.each { |user_id| worker.add(user_id: user_id, partner_id: partner.id, partner_manager_group_id: manager_group.id) }
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|