Created
May 28, 2014 19:13
-
-
Save veloper/569e3d7d5dd2a9ab7fed to your computer and use it in GitHub Desktop.
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 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