Skip to content

Instantly share code, notes, and snippets.

@carloscortegagna
carloscortegagna / foreign_keys_not_indexed
Created July 3, 2012 08:03
Rails: list foreign keys which aren't indexed
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
@carloscortegagna
carloscortegagna / external_link.css
Created July 3, 2012 07:38
CSS: style external domain links