调整迁移文件

dev_course
cxt 6 years ago
parent 953afbddaf
commit a6ec81eac4

@ -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

Loading…
Cancel
Save