Skip to content

Instantly share code, notes, and snippets.

@mothra
Forked from thetamind/example output
Last active December 16, 2015 00:39
Show Gist options
  • Save mothra/5349398 to your computer and use it in GitHub Desktop.
Save mothra/5349398 to your computer and use it in GitHub Desktop.
add_index :attachments, :parent_id
add_index :attachments, :asset_id
add_index :domain_names, :user_id
add_index :domain_names, :event_id
add_index :event_memberships, :user_id
add_index :event_memberships, :event_id
missing = {}
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{|index| index.columns.first}.uniq
unindexed = columns - indexed_columns
missing[t] = unindexed unless unindexed.empty?
end
missing.each do |table, columns|
columns.each do |col|
puts " add_index :#{table}, :#{col}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment