#Rails Indexes
Rails indexes is a small package of 2 rake tasks that scan your application models and displays a list of columns that probably should be indexed.
Note: there should be mode fields depending on your application design and custom queries.
Add rails_indexes to your Gemfile:
gem "rails_indexes", :git => "https://github.com/warpc/rails_indexes"
and install gem
bundle install
Display a migration for adding/removing all necessary indexes based on associations:
rake db:index_migration
Display a migration for adding/removing all necessary indexes based on AR::Base#find calls (including: find
, find_by
, find_all_by
, find_by_x_and_y
, find_all_by_x_and_y
):
rake db:find_query_indexes
Notice: At now moment it does not support Arel(the new Rails 3 Active Record Query Interface) calls (including: where, joins, includes, from, select...), but still usefull for indexes based on association
Note that add index in big database may take a long time.
Compatible with Ruby 1.9 and Rails 3.
- Support Arel(the new Rails 3 Active Record Query Interface) call for
find_query_indexes
action
Differences from the original rails_indexes
- Compatible with Ruby 1.9 and Rails 3
- Installing as Gem
- Analize
has_many :through
associations - Working STI analize
- Good test coverage with RSpec
- Do not suggest add index for primary key (about reason read below)
The primary key is always indexed. This is generally true for all storage engines that at all supports indices.
For this reason, no longer displays a gem suggestions about adding indexes to primary keys.
bundle install
rake
to run the tests.
All feedback, bug reports and thoughts on this gratefully received.
Elad Meidar - http://blog.eizesus.com
Thanks: Eric Davis - http://littlestreamsoftware.com
Released under the same license as Ruby. No Support. No Warranty, no Pain.