Skip to content

Commit

Permalink
Improve performance of migration
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleMacPherson committed Jan 15, 2025
1 parent eefc189 commit 51546b1
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions app/services/qualifications_migration.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
class QualificationsMigration
def self.perform
ActiveRecord::Base.transaction do
qualifications = Qualification.where(category: "other_secondary")

qualifications.find_each do |qualification|
results = qualification.qualification_results
results.each do |result|
Qualification.create!(category: "other", subject: result.subject, grade: result.grade, institution: qualification.institution, name: qualification.name,
year: qualification.year, job_application_id: qualification.job_application_id, jobseeker_profile_id: qualification.jobseeker_profile_id,
Qualification.includes(:qualification_results).where(category: "other_secondary").find_each(batch_size: 500) do |qualification|
qualification.qualification_results.each do |result|
Qualification.create!(category: "other", subject: result.subject, grade: result.grade,
institution: qualification.institution, name: qualification.name, year: qualification.year,
job_application_id: qualification.job_application_id, jobseeker_profile_id: qualification.jobseeker_profile_id,
finished_studying: qualification.finished_studying)
end

Expand Down

0 comments on commit 51546b1

Please sign in to comment.