From a6ec81eac4ac8eef7f61763169304eb93fba5d03 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 20 Jun 2019 20:24:24 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=BF=81=E7=A7=BB=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190309085449_migrate_course_members.rb | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/db/migrate/20190309085449_migrate_course_members.rb b/db/migrate/20190309085449_migrate_course_members.rb index 8e828610e..1d28eb5d1 100644 --- a/db/migrate/20190309085449_migrate_course_members.rb +++ b/db/migrate/20190309085449_migrate_course_members.rb @@ -1,21 +1,21 @@ 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