インデックスを貼った方が良いカラムを一発で抽出する方法はないか探していると良さげなGemを見つけたので紹介します。
plentz/lol_dba
まずgemをインストールして、
$ gem install lol_dba
次のコマンドを実行すると・・・
$ lol_dba db:find_indexes
* TIP: if you have a problem with the index name('index name too long') you can solve with the :name option. Something like :name => 'my_index'.
* run `rails g migration AddMissingIndexes` and add the following content:
class AddMissingIndexes < ActiveRecord::Migration
def change
add_index :users, :hoge_id
end
end
上記のように add_index :table_name, :column_id
という形でインデックスを貼った方が良いものを出力してくれます!
あとは $ rails g migration AddMissingIndexes
してコピペすればOKですね。
mysqlを使っているサービスで上記を実行したのですが、ソースをチラッと見た感じだと、mysql/sqlite/postgresのいずれでも大丈夫そうです。
ブログにも書いてます |д゚)チラッ
http://tackeyy.com/blog/posts/Introduction-of-lol_dba