Skip to content

Instantly share code, notes, and snippets.

@wilbert
Created June 18, 2015 20:20
Show Gist options
  • Save wilbert/1a4f0f587f65311f8760 to your computer and use it in GitHub Desktop.
Save wilbert/1a4f0f587f65311f8760 to your computer and use it in GitHub Desktop.
Normalize table and column names to downcase.
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