Database Index Optimization and Migration Maintenance

#53 Database Index Optimization and Migration Maintenance
11/6/2016

Summary

Adding indexes to your databases can increase the SQL search performance on your tables. As your application grows, migration files can become out of hand, use squasher to squish them down to a single file.
1
rails database performance

Summary

Terminalgem install lol_dba
cd <RAILS_PROJECT> 
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 :comments, :user_id
        add_index :comments, :post_id
        add_index :posts, :user_id
      end
    end
Terminal
gem install squasher
squasher YYYY/MM/DD