Forked from davygora/list_indexes_in_rails_console.rb
Created
January 4, 2024 22:56
-
-
Save davidimoore/1bfb8c1bc5f3fda98e089389731a2348 to your computer and use it in GitHub Desktop.
Get list of all indexes in rails console.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# rails console | |
ActiveRecord::Base.connection.tables.each do |table| | |
indexes = ActiveRecord::Base.connection.indexes(table) | |
if indexes.length > 0 | |
puts "====> #{table} <====" | |
indexes.each do |index| | |
puts "----> #{index.name}" | |
end | |
puts "====> #{table} <====" | |
2.times{ puts ''} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment