Skip to content

Instantly share code, notes, and snippets.

@rigelstpierre
Created December 10, 2012 04:19
Show Gist options
  • Save rigelstpierre/4248358 to your computer and use it in GitHub Desktop.
Save rigelstpierre/4248358 to your computer and use it in GitHub Desktop.
require 'digest/md5'
class RemoveDuplicateRecords < ActiveRecord::Migration
def self.up
addresses = {}
Listing.find_each do |listing|
digest = Digest::MD5.hexdigest("#{listing.street_address}#{listing.apartment_no}")
if addresses.include?(digest)
listing.destroy
else
addresses[digest] = true
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment