Skip to content

Instantly share code, notes, and snippets.

@durran
Created May 31, 2012 08:37
Show Gist options
  • Save durran/2841955 to your computer and use it in GitHub Desktop.
Save durran/2841955 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