You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/db/migrate/20200207090252_add_video_to...

13 lines
604 B

class AddVideoToCourseModule < ActiveRecord::Migration[5.2]
def change
Course.all.each do |course|
unless course.course_modules.exists?(module_type: "video")
atta_position = course.course_modules.find_by(module_type: 'attachment')&.position.to_i
video_position = atta_position != 0 ? (atta_position + 1) : 11
course.course_modules.where("position >= #{video_position}").update_all("position = position + 1")
course.course_modules << CourseModule.new(module_type: "video", hidden: 1, module_name: "视频", position: video_position)
end
end
end
end