Created
June 18, 2015 20:20
-
-
Save wilbert/1a4f0f587f65311f8760 to your computer and use it in GitHub Desktop.
Normalize table and column names to downcase.
This file contains hidden or 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
namespace :normalize do | |
desc "Nomalize table names" | |
task table_names: [:environment] do | |
ActiveRecord::Base.connection.tables.each do |table_name| | |
if table_name.match(/[A-Z]/) | |
ActiveRecord::Migration.rename_table table_name, table_name.downcase | |
end | |
end | |
end | |
desc "Normalize column names" | |
task column_names: [:environment] do | |
ActiveRecord::Base.connection.tables.each do |table_name| | |
ActiveRecord::Base.connection.columns(table_name).each do |c| | |
if c.name.match(/[A-Z]/) | |
ActiveRecord::Migration.rename_column table_name, c.name, c.name.downcase | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment