Module: OnlineMigrations::Migrator

Defined in:
lib/online_migrations/migrator.rb

Instance Method Summary collapse

Instance Method Details

#ddl_transaction(migration_or_proxy) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/online_migrations/migrator.rb', line 6

def ddl_transaction(migration_or_proxy)
  migration =
    if migration_or_proxy.is_a?(ActiveRecord::MigrationProxy)
      migration_or_proxy.send(:migration)
    else
      migration_or_proxy
    end

  if use_transaction?(migration)
    # Wrap the entire transaction with lock retries so that if the transaction
    # fails to acquire any locks, the whole migration is retried.
    # Note: at this point we don't have visibility into individual DDL commands,
    # so command and arguments will be nil when lock_timeout is called.
    # For command-specific retry behavior, migrations must use `disable_ddl_transaction!`
    migration.connection.with_lock_retries do
      super
    end
  else
    super
  end
end