lol_dba is a small package of rake tasks that scan your application models and displays a list of columns that probably should be indexed. Also, it can generate .sql migration scripts. Most of the code come from rails_indexes and migration_sql_generator.
To use lol_dba in the easiest way possible you have to do two things:
gem install lol_dba
Then run one of the following commands...
To display a migration for adding/removing all necessary indexes based on associations:
To generate .sql files for your migrations inside db/migrate_sql folder:
lol_dba db:migrate_sql # defaults to all migrations lol_dba db:migrate_sql[pending] # only pending migrations lol_dba db:migrate_sql # generate sql only for migration 20120221205526
If you want to use lol_dba with rake, you should do a few more steps:
Add lol_dba to your Gemfile
Run the install command
Use it the same way you use other rake commands
rake db:find_indexes rake db:migrate_sql # defaults to all migrations rake db:migrate_sql[pending] # only pending migrations rake db:migrate_sql # generate sql only for migration 20120221205526
Compatible with Ruby 2.x and Rails 4.x (for now, we still support Ruby 1.9 and Rails 3.x).
The primary key is always indexed. This is generally true for all storage engines that at all supports indices.
For this reason, we no longer suggest to add indexes to primary keys.
To run lol_dba tests, just clone the repo and run:
bundle install && rake
to run the tests.
All feedback, bug reports and thoughts on this gratefully received.
- Diego Plentz
- Elad Meidar
- Eric Davis
- Jay Fields
- Muness Alrubaie
- Vladimir Sharshov
- Fabio Rehm
- Emanuel Imhof
- Adrian Hooper
- Ray Zane
- Grant Gongaware
Lol DBA is released under the MIT license.