Created
April 29, 2022 12:50
-
-
Save jcreed/829b6cb7c4b8d007cc59eac1965789ec to your computer and use it in GitHub Desktop.
aamc staging
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
namespace :releases do | |
namespace 'one_offs' do | |
desc 'fix-genders - CASPA22: Delete test applicants from WebAdMIT - CASPA Test Organization' | |
task 'fix-genders': :environment do |task| | |
include ReleaseTaskHelpers | |
display :notice, task.full_comment | |
unless if Rails.configuration.is_aamc | |
GENDERS = ["MAN", "WOMAN", "OTHER"] | |
with_association('AMCAS', '2023') do |cas| | |
genders_keep = genders.where(association_id: cas.id, identifier: GENDERS).where("id < 40") | |
genders_remove = genders.where(association_id: cas.id).where("id > 39 and id < 49") | |
GENDERS.each do |gender| | |
keep_id = genders_keep.where(identifier: gender).id | |
removes = genders_remove.where(identifier: gender) | |
remove_ids = removes.map(&:id) | |
if keep_id.count == 1 && remove_ids.count == 3 | |
Detail.where(gender_id: remove_ids).update_all(gender_id: keep_id) | |
Guardian.where(gender_id: remove_ids).update_all(gender_id: keep_id) | |
Sibling.where(gender_id: remove_ids).update_all(gender_id: keep_id) | |
removes.delete_all | |
display :success, "Updated bad ids:#{remove_ids} to #{keep_id} cas #{cas.name}" | |
else | |
display :notice, "Unable to update #{gender} cas #{cas.name}" | |
end | |
end | |
end | |
with_association('AMCAS-SandBox', '2023') do |cas| | |
genders_keep = genders.where(association_id: cas.id, identifier: GENDERS).where("id < 52") | |
genders_remove = genders.where(association_id: cas.id).where("id > 51 and id < 61") | |
GENDERS.each do |gender| | |
keep_id = genders_keep.where(identifier: gender).id | |
removes = genders_remove.where(identifier: gender) | |
remove_ids = removes.map(&:id) | |
if keep_id.count == 1 && remove_ids.count == 3 | |
Detail.where(gender_id: remove_ids).update_all(gender_id: keep_id) | |
Guardian.where(gender_id: remove_ids).update_all(gender_id: keep_id) | |
Sibling.where(gender_id: remove_ids).update_all(gender_id: keep_id) | |
removes.delete_all | |
display :success, "Updated bad ids:#{remove_ids} to #{keep_id} cas #{cas.name}" | |
else | |
display :notice, "Unable to update #{gender} cas #{cas.name}" | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment