分班的position迁移

dev_tj
cxt 5 years ago
parent ed84abf94d
commit 52ab6eb9e7

@ -11,8 +11,8 @@ class MigrateCouresMemberGroup < ActiveRecord::Migration[5.2]
if CourseGroup.where(course_id: course.id, name: member.course_group_name).exists? if CourseGroup.where(course_id: course.id, name: member.course_group_name).exists?
new_group = CourseGroup.where(course_id: course.id, name: member.course_group_name).first new_group = CourseGroup.where(course_id: course.id, name: member.course_group_name).first
else else
position = CourseGroup.where(course_id: course.id).order("position desc").first&.position.to_i + 1 # position = CourseGroup.where(course_id: course.id).order("position desc").first&.position.to_i + 1
new_group = course.course_groups.create!(name: member.course_group_name, position: position) new_group = course.course_groups.create!(name: member.course_group_name)
course.exercise_group_settings.where(course_group_id: member.course_group_id).update_all(course_group_id: new_group.id) course.exercise_group_settings.where(course_group_id: member.course_group_id).update_all(course_group_id: new_group.id)
course.attachment_group_settings.where(course_group_id: member.course_group_id).update_all(course_group_id: new_group.id) course.attachment_group_settings.where(course_group_id: member.course_group_id).update_all(course_group_id: new_group.id)
HomeworkGroupReview.where(homework_common_id: course.homework_commons.pluck(:id)).where(course_group_id: member.course_group_id).update_all(course_group_id: new_group.id) HomeworkGroupReview.where(homework_common_id: course.homework_commons.pluck(:id)).where(course_group_id: member.course_group_id).update_all(course_group_id: new_group.id)

@ -0,0 +1,4 @@
class MigrateCourseGroupMemberCount < ActiveRecord::Migration[5.2]
def change
end
end

@ -0,0 +1,14 @@
class MigrateCoureGroupPosition < ActiveRecord::Migration[5.2]
def change
course_ids = [377, 657, 715, 777, 973, 1093, 1131, 1180, 1309, 1920, 2037, 2346, 2354, 2493, 2752, 2920, 3000,
3141, 3240, 3350, 3351, 3353, 3387, 3533, 3796]
courses = Course.where(id: course_ids)
courses.each do |course|
CourseGroup.where(coures_id: course.id).reorder("position ASC, CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").each_with_index do |group, index|
group.update!(position: index+1)
end
end
end
end
Loading…
Cancel
Save