Skip to content

Instantly share code, notes, and snippets.

@eftakhairul
Created October 3, 2014 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eftakhairul/fbd4073452047ce859a8 to your computer and use it in GitHub Desktop.
Save eftakhairul/fbd4073452047ce859a8 to your computer and use it in GitHub Desktop.
migration
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