Module: PgSaurus::CreateIndexConcurrently::Migrator
- Defined in:
- lib/pg_saurus/create_index_concurrently.rb
Overview
Run postponed index creation for each migration.
This module included into (see ::ActiveRecord::Migrator) class to make possible to execute queries for postponed index creation after closing migration’s transaction.
Instance Method Summary collapse
-
#ddl_transaction(*args, &block) ⇒ Object
Override (see ::ActiveRecord::Migrator.ddl_transaction) to call (see ::PgSaurus::CreateIndexConcurrently::Migration.process_postponed_queries) immediately after transaction.
Instance Method Details
#ddl_transaction(*args, &block) ⇒ Object
Override (see ::ActiveRecord::Migrator.ddl_transaction) to call (see ::PgSaurus::CreateIndexConcurrently::Migration.process_postponed_queries) immediately after transaction.
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/pg_saurus/create_index_concurrently.rb', line 154 def ddl_transaction(*args, &block) super(*args, &block) # GOTCHA: # This might be a bit tricky, but I've decided that this is the best # way to retrieve migration instance after closing transaction. # The problem that (see ::ActiveRecord::Migrator) doesn't provide any # access to recently launched migration. All logic to iterate through # set of migrations incapsulated in (see ::ActiveRecord::Migrator.migrate) # method. # So, to get access to migration you need to override `migrate` method # and duplicated all logic inside it, plus add call to # `process_postponed_queries`. # I've decided this is less forward compatible then retrieving # value of `migration` variable in context where block # given to `ddl_transaction` method was created. # -- zekefast 2012-09-12 migration = block.binding.eval('migration') migration.process_postponed_queries end |