Skip to content

warpc/rails_indexes

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#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.

Installation

Add rails_indexes to your Gemfile:

gem "rails_indexes", :git => "https://github.com/warpc/rails_indexes"

and install gem

bundle install

Usage

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.

Compatibility

Compatible with Ruby 1.9 and Rails 3.

Upcoming features/enhancements

  • 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)

About primary_key

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.

Tests

bundle install
rake

to run the tests.

Feedback

All feedback, bug reports and thoughts on this gratefully received.

Author:

Elad Meidar - http://blog.eizesus.com

Thanks: Eric Davis - http://littlestreamsoftware.com

License

Released under the same license as Ruby. No Support. No Warranty, no Pain.

About

A rake task to track down missing database indexes. does not assume that all foreign keys end with the convention of _id.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%