-
-
Notifications
You must be signed in to change notification settings - Fork 503
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
.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 |
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.
Always better to do
save!
in case something goes wrong.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.
Excellent catch! It turns out that this is going to be blocked by whatever pickup emails are still wrong. (Le Sigh.)
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 suppose we could use update_attribute! ? Let me see how widespread the pickup email actually is
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.
There are also some that don't pass because of the rule about social media (which, I presume, haven't been changed since we added that rule.) All told, about 40 partners that are currently invalid. About a dozen of them are non-trivial. Let's talk Sunday.