From 4a86b86021d5ff2c323b06c8bf24797863b5d5fd Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 14:29:24 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E8=AF=BE=E5=A0=82=E5=88=86?= =?UTF-8?q?=E7=8F=ADposition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190720062632_migrate_course_group_position.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 db/migrate/20190720062632_migrate_course_group_position.rb diff --git a/db/migrate/20190720062632_migrate_course_group_position.rb b/db/migrate/20190720062632_migrate_course_group_position.rb new file mode 100644 index 000000000..9b78c2e29 --- /dev/null +++ b/db/migrate/20190720062632_migrate_course_group_position.rb @@ -0,0 +1,11 @@ +class MigrateCourseGroupPosition < ActiveRecord::Migration[5.2] + def change + 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 + end +end