Merge branch 'dev_course' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_course

dev_course
jingquan huang 6 years ago
commit 9dc64c9993

@ -1,27 +1,27 @@
class MigrateCourseMembers < ActiveRecord::Migration[5.2] class MigrateCourseMembers < ActiveRecord::Migration[5.2]
def change def change
add_column :course_groups, :position, :integer, default: 0 # add_column :course_groups, :position, :integer, default: 0
#
Course.find_each do |course| # Course.find_each do |course|
position = 1 # position = 1
course.course_groups.reorder("CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").find_each do |group| # course.course_groups.reorder("CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").find_each do |group|
group.update_attribute(:position, position) # group.update_attribute(:position, position)
position += 1 # position += 1
end # end
end # end
#
#
add_column :course_groups, :course_members_count, :integer, default: 0 # add_column :course_groups, :course_members_count, :integer, default: 0
#
CourseGroup.find_each do |g| # CourseGroup.find_each do |g|
CourseGroup.reset_counters g.id, :course_members # CourseGroup.reset_counters g.id, :course_members
end # end
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
Member.where("course_id != -1").find_each do |member| Member.where("course_id != -1").find_each do |member|
if member.course && member.user if member.course && member.user
puts(member.course_id) puts(member.id)
member.member_roles.each do |role| 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)) 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 member_group_id = role.role_id == 10 ? member.course_group_id : 0

Loading…
Cancel
Save