Skip to content

Instantly share code, notes, and snippets.

@shedd
Forked from durran/indexes.rb
Created August 8, 2012 08:30
Show Gist options
  • Save shedd/3293421 to your computer and use it in GitHub Desktop.
Save shedd/3293421 to your computer and use it in GitHub Desktop.
Missing FK indexes
connection = ActiveRecord::Base.connection
connection.tables.each do |table|
columns = connection.columns(table).collect(&:name).select {|x| x.ends_with?("_id" || x.ends_with("_type"))}
indexed_columns = connection.indexes(table).collect(&:columns).flatten.uniq
unindexed = columns - indexed_columns
unless unindexed.empty?
puts "#{table}: #{unindexed.join(", ")}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment