|
| 1 | +class CleanupPartnerAgencyTypes < ActiveRecord::Migration[7.1] |
| 2 | + # based on veesus' work in PR 4261 |
| 3 | + |
| 4 | + def up |
| 5 | + # Some agency types have trailing spaces -- need tp get rid of them first |
| 6 | + |
| 7 | + update 'UPDATE partner_profiles SET agency_type = TRIM(agency_type)' |
| 8 | + |
| 9 | + |
| 10 | + mapping = [['Vocational training program','CAREER'], |
| 11 | + ['Church','CHURCH'], |
| 12 | + ['Church','CHURCH'], |
| 13 | + ['Church ministry','CHURCH'], |
| 14 | + ['Crisis/Disaster services','CRISIS'], |
| 15 | + ['Domestic Violence/Non-Profit','DOMV'], |
| 16 | + ['Child Care Center','ECE'], |
| 17 | + ['Education','EDU'], |
| 18 | + ['Educational','EDU'], |
| 19 | + ['Non-Profit - Education','EDU'], |
| 20 | + ['public elementary school','ES'], |
| 21 | + ['Church food pantry','FOOD'], |
| 22 | + ['Food bank','FOOD'], |
| 23 | + ['Food pantry','FOOD'], |
| 24 | + ['Food Pantry','FOOD'], |
| 25 | + ['Food Pantry - Emergency Diaper Distribution','FOOD'], |
| 26 | + ['Foster Care','FOSTER'], |
| 27 | + ['Government Agency/Affiliate','GOVT'], |
| 28 | + ['Community health program','HEALTH'], |
| 29 | + ['Home visits','HOMEVISIT'], |
| 30 | + ['Public School','HS'], |
| 31 | + ['Infant/Child Pantry/Closet','INFPAN'], |
| 32 | + ['ASO','HEALTH'], |
| 33 | + ['Case Management','OUTREACH'], |
| 34 | + ['Child Advocacy Center','CHILD'], |
| 35 | + ['Child Placing Agency','FOSTER'], |
| 36 | + ['Community Ministry','CHURCH'], |
| 37 | + ['Community outreach services','OUTREACH'], |
| 38 | + ['Community Service Organization','OUTREACH'], |
| 39 | + ['Diaper agency','BNB'], |
| 40 | + ['Diaper Bank','BNB'], |
| 41 | + ['Emergency Crisis/Human Trafficking/Refuee Service','REF'], |
| 42 | + ['Human Services','OUTREACH'], |
| 43 | + ['Maternity Home','PREG'], |
| 44 | + ['Mental Health','MHEALTH'], |
| 45 | + ['Non-Profit Victim Services and Family Resource Center','FAMILY'], |
| 46 | + ['Non-Profit. Clothing, Food and Diaper Assistance','INFPAN'], |
| 47 | + ['Nonprofit/School','EDU'], |
| 48 | + ['Perinatal Mental Health Peer Support','MHEALTH'], |
| 49 | + ['Primary Care Doctor','HEALTH'],['Public Health','HEALTH'], |
| 50 | + ['Reproductive Health Care, Maternity Services','PREG'], |
| 51 | + ['Safety Net Organization','OUTREACH'], |
| 52 | + ['School','District'], |
| 53 | + ['School District','District'], |
| 54 | + ['School District','District'], |
| 55 | + ['Women Substance Abuse','TREAT'], |
| 56 | + ['Law Enforcement Agency','POLICE'], |
| 57 | + ['Pregnancy Center - Charitable Health','PREG'], |
| 58 | + ['Nonprofit preschool','PRESCH'], |
| 59 | + ['Child abuse resource center','ABUSE'], |
| 60 | + ['Career technical training','CAREER'], |
| 61 | + ['Community development corporation','CDC'], |
| 62 | + ['Early childhood services','CHILD'], |
| 63 | + ['Church outreach ministry','CHURCH'], |
| 64 | + ['Developmental disabilities program','DISAB'], |
| 65 | + ['Domestic violence shelter','DOMV'], |
| 66 | + ['Education program','EDU'], |
| 67 | + ['School - Elementary School','ES'], |
| 68 | + ['Family resource center','FAMILY'], |
| 69 | + ['Food bank/pantry','FOOD'], |
| 70 | + ['Head Start/Early Head Start','HEADSTART'], |
| 71 | + ['Community health program or clinic','HEALTH'], |
| 72 | + ['Homeless resource center','HOMELESS'], |
| 73 | + ['Hospital','HOSP'], |
| 74 | + ['Hospital','HOSP'], |
| 75 | + ['School - High School','HS'], |
| 76 | + ['Correctional Facilities / Jail / Prison / Legal System','LEGAL'], |
| 77 | + ['School - Middle School','MS'], |
| 78 | + ['Pregnancy resource center','PREG'], |
| 79 | + ['Pregnancy Resource Center','PREG'], |
| 80 | + ['Refugee resource center','REF'], |
| 81 | + ['Treatment clinic','TREAT'], |
| 82 | + ['Women, Infants and Children','WIC']] |
| 83 | + |
| 84 | + mapping.each do |type_pair| |
| 85 | + profiles = Partners::Profile.where(agency_type: type_pair[0]) |
| 86 | + profiles.each do |profile| |
| 87 | + profile.agency_type = Partner::AGENCY_TYPES[type_pair[1]] |
| 88 | + profile.save! |
| 89 | + end |
| 90 | + |
| 91 | + end |
| 92 | + |
| 93 | + |
| 94 | + profiles = Partners::Profile |
| 95 | + .where.not(agency_type: Partner::AGENCY_TYPES.values) |
| 96 | + .in_batches |
| 97 | + |
| 98 | + profiles.each_record do |profile| |
| 99 | + profile.other_agency_type = profile.agency_type |
| 100 | + profile.agency_type = Partner::AGENCY_TYPES['OTHER'] |
| 101 | + profile.save! |
| 102 | + end |
| 103 | + |
| 104 | + end |
| 105 | + |
| 106 | + def down |
| 107 | + # Irreversible data migration |
| 108 | + end |
| 109 | +end |
0 commit comments