-
-
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
Partner Profile : clean up social media, request types and pick up emails #4829
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
61 changes: 61 additions & 0 deletions
61
db/migrate/20241204111437_cleanup_invalid_partner_profiles.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,61 @@ | ||
class CleanupInvalidPartnerProfiles < ActiveRecord::Migration[7.1] | ||
def up | ||
# ActiveRecord::Base.logger = Logger.new(STDOUT) | ||
invalid_profiles = Partners::Profile.all.reject(&:valid?) | ||
|
||
return if !invalid_profiles.present? | ||
|
||
invalid_profiles.each do |profile| | ||
# address invalid social media section | ||
|
||
unless (profile.website.present? || | ||
profile.twitter.present? || | ||
profile.facebook.present? || | ||
profile.instagram.present? || | ||
profile.no_social_media_presence || | ||
profile.partner.partials_to_show.exclude?("media_information")) | ||
profile.no_social_media_presence = true | ||
end | ||
|
||
# address no request types set | ||
|
||
unless(profile.enable_quantity_based_requests || profile.enable_individual_requests || profile.enable_child_based_requests) | ||
profile.enable_quantity_based_requests = profile.partner.organization.enable_quantity_based_requests | ||
profile.enable_individual_requests = profile.partner.organization.enable_individual_requests | ||
profile.enable_child_based_requests = profile.partner.organization.enable_child_based_requests | ||
end | ||
|
||
|
||
|
||
# address bad pickup email | ||
|
||
unless profile.valid? | ||
# if profile is not valid at this point, it is a bad pickup email | ||
|
||
pick_up = profile.pick_up_email | ||
pick_up.downcase! | ||
pick_up.strip! | ||
if pick_up == "none" or pick_up == "na" or pick_up == "n/a" or pick_up == "see above" | ||
profile.pick_up_email = "" | ||
else | ||
profile.pick_up_email.gsub!("/",",") | ||
profile.pick_up_email.gsub!(";",",") | ||
profile.pick_up_email.gsub!(" or ", ", ") | ||
profile.pick_up_email.gsub!(" and ", ", ") | ||
profile.pick_up_email.gsub!(" & ", ", ") | ||
end | ||
|
||
if(!profile.valid?) ## If we can't fix the email, append it to the name so we don't lose the information aspect | ||
profile.pick_up_name += ", email: " + profile.pick_up_email | ||
profile.pick_up_email = "" | ||
end | ||
end | ||
|
||
profile.save! | ||
|
||
end | ||
end | ||
def down | ||
# irreversible | ||
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.
One other question. Are there many
Partners::Profile
records in production? If there are many, then loading them all at once like this could cause a memory spike and fire off thousands of database queries.The safer option when dealing with lots of records would be using something like find_each:
If there aren't many records it doesn't really matter and ignore this comment.
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.
Define many g. There are about 6000.
I have been testing this against prod data, and it will run during a maintenance window,
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.
find_each is technically better, but for a one-off migration like this it's usually not worth the fuss.