rails database indexes made easy

So on ClashProgress I wanted to add indexes to my application to help with slow running queries. And by a stroke of luck, I found this gem called lol_dba.

I followed their incredibly easy setup.

Gemfile

gem 'lol_dba'

Terminal Commands

$ bundle

$rake db:find_indexes

And in the terminal I received the following output which I just dropped into a migration file and ran $rake db:migrate!

    class AddMissingIndexes < ActiveRecord::Migration
      def change
        addindex :friendships, [:userid, :userid]
        addindex :friendships, [:friendid, :friendid]
        addindex :friendships, :userid
        addindex :friendships, :friendid
        addindex :accounts, :userid
        addindex :builders, :userid
        addindex :buildings, :userid
        addindex :buildings, :townhallid
        addindex :buildings, :name
        addindex :buildings, :[:name, :level]
        addindex :buildings, :townhalllevel
        addindex :buildingavailabilities, :name
        addindex :pgsearchdocuments, [:["searchableid", "searchabletype"]]
        addindex :posts, :categoryid
        addindex :posts, :userid
        addindex :townhalls, :userid
        addindex :walls, :userid
        addindex :walls, :townhallid
        addindex :walls, :[:name, :level]
        addindex :walls, :uniquewallcode
        addindex :wallgoals, :userid
      end
    end

Post Content