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/20190911020749_migrate_shix...

19 lines
769 B

class MigrateShixunStudentWork < ActiveRecord::Migration[5.2]
def change
homework_commons = HomeworkCommon.where(homework_type: 4).where("created_at > '2019-07-01 00:00:00'")
attrs = %i[homework_common_id user_id created_at updated_at]
StudentWork.bulk_insert(*attrs) do |worker|
homework_commons.each do |homework|
course = homework.course
if course && homework.student_works.count != course.students.count
course.students.each do |student|
next if StudentWork.where(homework_common_id: homework.id, user_id: student.user_id).any?
same_attrs = {user_id: student.user_id}
worker.add same_attrs.merge(homework_common_id: homework.id)
end
end
end
end
end
end