ActiveRecord finding existing table indexes

Just an update for cleaner inspection. As I had many tables I was finding it difficult to search for specific stuffs.

  ActiveRecord::Base.connection.tables.each do |table|
  indexes = ActiveRecord::Base.connection.indexes(table)
  if indexes.length > 0
    puts "====>  #{table} <===="
    indexes.each do |ind|
      puts "----> #{ind.name}"
    end
    puts "====>  #{table} <===="
    2.times{ puts ''}
  end
end

This will be of quick setup.


This works with MySQL, SQLite3, and Postgres:

ActiveRecord::Base.connection.tables.each do |table|
    puts ActiveRecord::Base.connection.indexes(table).inspect
end

But I think it only gives you the indexes you specifically created.

Also, to find out which adapter is in use:

ActiveRecord::Base.connection.class