Skip to content
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
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/models/partner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class Partner < ApplicationRecord
AGENCY_TYPES = {
"CAREER" => "Career technical training",
"ABUSE" => "Child abuse resource center",
"BNB" => "Basic Needs Bank",
"CHURCH" => "Church outreach ministry",
"COLLEGE" => "College and Universities",
"CDC" => "Community development corporation",
Expand All @@ -82,6 +83,7 @@ class Partner < ApplicationRecord
"LEGAL" => "Correctional Facilities / Jail / Prison / Legal System",
"CRISIS" => "Crisis/Disaster services",
"DISAB" => "Developmental disabilities program",
"DISTRICT" => "School District",
"DOMV" => "Domestic violence shelter",
"ECE" => "Early Childhood Education/Childcare",
"CHILD" => "Early childhood services",
Expand All @@ -96,6 +98,7 @@ class Partner < ApplicationRecord
"HOSP" => "Hospital",
"INFPAN" => "Infant/Child Pantry/Closet",
"LIB" => "Library",
"MHEALTH" => "Mental Health",
"MILITARY" => "Military Bases/Veteran Services",
"POLICE" => "Police Station",
"PREG" => "Pregnancy resource center",
Expand Down
109 changes: 109 additions & 0 deletions db/migrate/20241122201255_cleanup_partner_agency_types.rb
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
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.)

Copy link
Collaborator Author

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

Copy link
Collaborator Author

@cielf cielf Nov 27, 2024

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.

end

end


profiles = Partners::Profile
.where.not(agency_type: Partner::AGENCY_TYPES.values)
Copy link
Collaborator

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, not values?

Copy link
Collaborator Author

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.

.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