-
-
Notifications
You must be signed in to change notification settings - Fork 508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migration for partner agency cleanup re issue 4241. Necessary step, … #4801
Merged
dorner
merged 3 commits into
rubyforgood:main
from
cielf:partner_agency_type_mapping_cleanup
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
109 changes: 109 additions & 0 deletions
109
db/migrate/20241122201255_cleanup_partner_agency_types.rb
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,109 @@ | ||
class CleanupPartnerAgencyTypes < ActiveRecord::Migration[7.1] | ||
# based on veesus' work in PR 4261 | ||
|
||
def up | ||
# Some agency types have trailing spaces -- need tp get rid of them first | ||
|
||
update 'UPDATE partner_profiles SET agency_type = TRIM(agency_type)' | ||
|
||
|
||
mapping = [['Vocational training program','CAREER'], | ||
['Church','CHURCH'], | ||
['Church','CHURCH'], | ||
['Church ministry','CHURCH'], | ||
['Crisis/Disaster services','CRISIS'], | ||
['Domestic Violence/Non-Profit','DOMV'], | ||
['Child Care Center','ECE'], | ||
['Education','EDU'], | ||
['Educational','EDU'], | ||
['Non-Profit - Education','EDU'], | ||
['public elementary school','ES'], | ||
['Church food pantry','FOOD'], | ||
['Food bank','FOOD'], | ||
['Food pantry','FOOD'], | ||
['Food Pantry','FOOD'], | ||
['Food Pantry - Emergency Diaper Distribution','FOOD'], | ||
['Foster Care','FOSTER'], | ||
['Government Agency/Affiliate','GOVT'], | ||
['Community health program','HEALTH'], | ||
['Home visits','HOMEVISIT'], | ||
['Public School','HS'], | ||
['Infant/Child Pantry/Closet','INFPAN'], | ||
['ASO','HEALTH'], | ||
['Case Management','OUTREACH'], | ||
['Child Advocacy Center','CHILD'], | ||
['Child Placing Agency','FOSTER'], | ||
['Community Ministry','CHURCH'], | ||
['Community outreach services','OUTREACH'], | ||
['Community Service Organization','OUTREACH'], | ||
['Diaper agency','BNB'], | ||
['Diaper Bank','BNB'], | ||
['Emergency Crisis/Human Trafficking/Refuee Service','REF'], | ||
['Human Services','OUTREACH'], | ||
['Maternity Home','PREG'], | ||
['Mental Health','MHEALTH'], | ||
['Non-Profit Victim Services and Family Resource Center','FAMILY'], | ||
['Non-Profit. Clothing, Food and Diaper Assistance','INFPAN'], | ||
['Nonprofit/School','EDU'], | ||
['Perinatal Mental Health Peer Support','MHEALTH'], | ||
['Primary Care Doctor','HEALTH'],['Public Health','HEALTH'], | ||
['Reproductive Health Care, Maternity Services','PREG'], | ||
['Safety Net Organization','OUTREACH'], | ||
['School','District'], | ||
['School District','District'], | ||
['School District','District'], | ||
['Women Substance Abuse','TREAT'], | ||
['Law Enforcement Agency','POLICE'], | ||
['Pregnancy Center - Charitable Health','PREG'], | ||
['Nonprofit preschool','PRESCH'], | ||
['Child abuse resource center','ABUSE'], | ||
['Career technical training','CAREER'], | ||
['Community development corporation','CDC'], | ||
['Early childhood services','CHILD'], | ||
['Church outreach ministry','CHURCH'], | ||
['Developmental disabilities program','DISAB'], | ||
['Domestic violence shelter','DOMV'], | ||
['Education program','EDU'], | ||
['School - Elementary School','ES'], | ||
['Family resource center','FAMILY'], | ||
['Food bank/pantry','FOOD'], | ||
['Head Start/Early Head Start','HEADSTART'], | ||
['Community health program or clinic','HEALTH'], | ||
['Homeless resource center','HOMELESS'], | ||
['Hospital','HOSP'], | ||
['Hospital','HOSP'], | ||
['School - High School','HS'], | ||
['Correctional Facilities / Jail / Prison / Legal System','LEGAL'], | ||
['School - Middle School','MS'], | ||
['Pregnancy resource center','PREG'], | ||
['Pregnancy Resource Center','PREG'], | ||
['Refugee resource center','REF'], | ||
['Treatment clinic','TREAT'], | ||
['Women, Infants and Children','WIC']] | ||
|
||
mapping.each do |type_pair| | ||
profiles = Partners::Profile.where(agency_type: type_pair[0]) | ||
profiles.each do |profile| | ||
profile.agency_type = Partner::AGENCY_TYPES[type_pair[1]] | ||
profile.save! | ||
end | ||
|
||
end | ||
|
||
|
||
profiles = Partners::Profile | ||
.where.not(agency_type: Partner::AGENCY_TYPES.values) | ||
.in_batches | ||
|
||
profiles.each_record do |profile| | ||
profile.other_agency_type = profile.agency_type | ||
profile.agency_type = Partner::AGENCY_TYPES['OTHER'] | ||
profile.save! | ||
end | ||
|
||
end | ||
|
||
def down | ||
# Irreversible data migration | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be
keys
, notvalues
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get why you would think that - but what is currently stored in the db is the values not the keys. Probably as a legacy from when it was a free-form field.