ManageIQ/manageiq — pull request #1271 by jrafanie (2014-12-22 21:27:05+00:00)
Title: WIP: Migration to add missing indexes.

TODO: We need to review if we need these indexes or not.
TODO: We need to add the :name for any indexes that are too long, see #1170

Replaces #1170

I ran the following code in rails console after migrating to get a list of bigint *_id columns without indexes:

```ruby
tables = ActiveRecord::Base.connection.tables
indexes = {}
tables.each do |t|
ActiveRecord::Base.connection.columns(t).each do |c|
next if c.sql_type != "bigint" || !c.name.ends_with?("_id")
index_found = ActiveRecord::Base.connection.indexes(t).any? do |i|
i.columns.include?(c.name)
end

unless index_found
indexes[t] ||= []
indexes[t] << c.name
end
end
end

indexes.keys.sort.each do |key|
columns = indexes[key]
puts [key.to_sym, columns.collect(&:to_sym)].inspect
end
```