Skip to content

Instantly share code, notes, and snippets.

@nesquena
Created July 14, 2011 00:11
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save nesquena/1081618 to your computer and use it in GitHub Desktop.
Save nesquena/1081618 to your computer and use it in GitHub Desktop.
Add concurrent index in Postgres Rails migration
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
@thatandyrose
Copy link

Thank you for this! Have you had any problems with it since you wrote this?

@thatandyrose
Copy link

Another quick question. Why not put the execute END/BEGIN inside the add_pg_index method?

@nathany
Copy link

nathany commented Aug 19, 2013

I'm guessing that's a hack to break out of the transaction? http://robots.thoughtbot.com/post/56828751507/how-to-create-postgres-indexes-concurrently-in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment