迁移文件的调整

dev_forum
cxt 6 years ago
parent 004c15be3e
commit d19cf56e38

@ -19,15 +19,13 @@ class MigrateCourseMembers < ActiveRecord::Migration[5.2]
ActiveRecord::Base.transaction do
begin
Member.where("course_id != -1").find_each do |member|
if member.course && member.user
puts(member.id)
member.member_roles.each do |role|
course_member_role = role.role_id == 3 ? 1 : (role.role_id == 9 ? 2 : (role.role_id == 7 ? 3 : 4))
member_group_id = role.role_id == 10 ? member.course_group_id : 0
CourseMember.create!(course_id: member.course_id, user_id: member.user_id, course_group_id: member_group_id.to_i,
graduation_group_id: member.graduation_group_id.to_i, role: course_member_role, is_active: role.is_current)
end
Member.where("course_id != -1").includes(:member_roles).find_each(batch_size: 500) do |member|
puts(member.id)
member.member_roles.each do |role|
course_member_role = role.role_id == 3 ? 1 : (role.role_id == 9 ? 2 : (role.role_id == 7 ? 3 : 4))
member_group_id = role.role_id == 10 ? member.course_group_id : 0
CourseMember.create!(course_id: member.course_id, user_id: member.user_id, course_group_id: member_group_id,
graduation_group_id: member.graduation_group_id, role: course_member_role, is_active: role.is_current)
end
end
rescue Exception => e

Loading…
Cancel
Save