I want to add an index to a production database. Fortunately we're running Postgres, which nicely allows concurrent indexing, so we can add an index without downtime. The catch -- concurrent indexes cannot be added from within a transaction, and rails migrations wrap everything inside a transaction.
Fortunately, there is something that looks like a really simple solution: overwrite the ActiveRecord::Migration private method ddl_transaction, as explained here.
class IndexUsersEmails < ActiveRecord::Migration
def ddl_transaction(&block)
block.call # do not start a transaction
end
def self.up
execute "CREATE INDEX CONCURRENTLY index_users_on_email ON users(email)"
end
end
The problem is that it does not seem to work in Rails 3.1. I do exactly what the code in the Gist does, and rails appears to completely ignore it. Any ideas on where to go with this?