Skip to content

Instantly share code, notes, and snippets.

@elskwid
Created September 30, 2009 18:03
Show Gist options
  • Save elskwid/198298 to your computer and use it in GitHub Desktop.
Save elskwid/198298 to your computer and use it in GitHub Desktop.
Rake task to check column names against oracle reserved words
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