Created
May 31, 2012 08:37
-
-
Save durran/2841955 to your computer and use it in GitHub Desktop.
Missing FK indexes
This file contains 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
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