Created
September 3, 2014 14:39
-
-
Save ethangunderson/1d08b4cef049266727e6 to your computer and use it in GitHub Desktop.
Find potential missing foreign key indexes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActiveRecord::Base.logger = nil | |
connection = ActiveRecord::Base.connection; nil | |
connection.tables.each do |table| | |
columns = connection.columns(table).map(&:name).select {|x| x.ends_with?("_id")} | |
indexed_columns = connection.indexes(table).map(&:columns).flatten.uniq | |
unindexed = columns - indexed_columns | |
unless unindexed.empty? | |
puts "#{table}: #{unindexed.join(", ")}" | |
end | |
nil | |
end; nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment