-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add migration to change other_secondary qualifications to other quali…
…fications
- Loading branch information
1 parent
6b00a68
commit eefc189
Showing
3 changed files
with
72 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,21 @@ | ||
class QualificationsMigration | ||
def self.perform | ||
ActiveRecord::Base.transaction do | ||
qualifications = Qualification.where(category: 'other_secondary') | ||
qualifications = Qualification.where(category: "other_secondary") | ||
|
||
qualifications.find_each do |qualification| | ||
# Get associated qualification results | ||
results = qualification.qualification_results | ||
results.each do |result| | ||
# Create a new qualification with category 'other' | ||
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 | ||
) | ||
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 | ||
|
||
# Delete the original qualification | ||
qualification.destroy! | ||
end | ||
end | ||
rescue => e | ||
rescue StandardError => e | ||
Rails.logger.error("Error migrating qualifications: #{e.message}") | ||
raise | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace :qualifications do | ||
desc "Migrate other_secondary qualifications to other category" | ||
task migrate_to_other: :environment do | ||
QualificationsMigration.perform | ||
puts "Migration completed successfully." | ||
rescue StandardError => e | ||
puts "Migration failed: #{e.message}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters