diff --git a/db/migrate/20190309085449_migrate_course_members.rb b/db/migrate/20190309085449_migrate_course_members.rb index ef8741bfb..8e828610e 100644 --- a/db/migrate/20190309085449_migrate_course_members.rb +++ b/db/migrate/20190309085449_migrate_course_members.rb @@ -1,27 +1,27 @@ class MigrateCourseMembers < ActiveRecord::Migration[5.2] def change - add_column :course_groups, :position, :integer, default: 0 - - Course.find_each do |course| - position = 1 - course.course_groups.reorder("CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").find_each do |group| - group.update_attribute(:position, position) - position += 1 - end - end - - - add_column :course_groups, :course_members_count, :integer, default: 0 - - CourseGroup.find_each do |g| - CourseGroup.reset_counters g.id, :course_members - end + # add_column :course_groups, :position, :integer, default: 0 + # + # Course.find_each do |course| + # position = 1 + # course.course_groups.reorder("CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").find_each do |group| + # group.update_attribute(:position, position) + # position += 1 + # end + # end + # + # + # add_column :course_groups, :course_members_count, :integer, default: 0 + # + # CourseGroup.find_each do |g| + # CourseGroup.reset_counters g.id, :course_members + # end ActiveRecord::Base.transaction do begin Member.where("course_id != -1").find_each do |member| if member.course && member.user - puts(member.course_id) + 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