Skip to content

Instantly share code, notes, and snippets.

@mulder
Forked from elskwid/check_column_names.rb
Created December 6, 2010 15:33
Show Gist options
  • Save mulder/730441 to your computer and use it in GitHub Desktop.
Save mulder/730441 to your computer and use it in GitHub Desktop.
namespace :oracle do
desc "Check column names against the oracle reserved words"
task :check_column_names => [:environment] do |t|
if ActiveRecord::Base.connection.adapter_name =~ /oracle/i
found = []
ActiveRecord::Base.connection.tables.each do |table_name|
model = table_name.singularize.classify.constantize rescue nil
model.columns.each do |column|
if ActiveRecord::ConnectionAdapters::OracleEnhancedReservedWords::RESERVED_WORDS[column.name.to_s.upcase]
found << "Table: #{table_name}, Column: #{column.name}"
end
end if model
end
unless found.empty?
puts "Reserved words found:"
found.each{|f| puts " - #{f}"}
end
else
puts "You must be using an oracle adapter to run this task"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment