Skip to content

Instantly share code, notes, and snippets.

@ttrmw
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ttrmw/8384e62f95937433a4fa to your computer and use it in GitHub Desktop.
Save ttrmw/8384e62f95937433a4fa to your computer and use it in GitHub Desktop.
list unindexed foreign keys in rails
c = ActiveRecord::Base.connection
c.tables.collect do |t|
columns = c.columns(t).collect(&:name).select {|x| x.ends_with?("_id" || x.ends_with("_type"))}
indexed_columns = c.indexes(t).collect(&:columns).flatten.uniq
unindexed = columns - indexed_columns
unless unindexed.empty?
puts "#{t}: #{unindexed.join(", ")}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment