Created
October 3, 2014 13:58
-
-
Save eftakhairul/fbd4073452047ce859a8 to your computer and use it in GitHub Desktop.
migration
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
class RemoveOldDuplicatePhoneNumberReference < ActiveRecord::Migration | |
def change | |
#fetch all user and remove the cross reference for duplicate phone number | |
User.real_users.find_in_batches.each(:batch_size => 100) do |batch| | |
batch.each do |u| | |
if u.annotations[:users_with_the_same_phone] | |
# remove other users' reference who are associated with this user | |
u.remove_reference_from_other_users_for_duplicate_phone | |
#remove reference from self | |
u.users_with_the_same_phone(reset:true) | |
u.save validation:false | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment