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.
13 lines
604 B
13 lines
604 B
5 years ago
|
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
|