Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save veloper/569e3d7d5dd2a9ab7fed to your computer and use it in GitHub Desktop.
Save veloper/569e3d7d5dd2a9ab7fed to your computer and use it in GitHub Desktop.
class NormalizeNetworkSupplierWebsites < ActiveRecord::Migration
class NetworkSuppliersTable < ActiveRecord::Base
self.table_name = "network_suppliers"
end
def up
NetworkSuppliersTable.where("website IS NOT NULL").find_each do |record|
record.website = record.website.to_s.split.grep(UrlValidator::REGULAR_EXPRESSION).first # The first valid website or nil
record.save! if record.changed?
end
end
def down
raise ActiveRecord::IrreversibleMigration
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment