module Cell::Ext::Migration::ContextTracker

OK, ContextTracker keeps up with:

* The context in which this migration is being ran, e.g. the :global first pass, the
  :prototype second pass, OR the :targeted per tenant pass.
* If it's in a global block or not, which determines if actions are actually executed
* If force_execution is set, which is for the benefit of playing back CommandRecorder
  commands.

Public Instance Methods

execute_ddl?() click to toggle source
# File lib/cell/ext/migration.rb, line 39
def execute_ddl?
  force_execution ||
  (pass_context == :global    &&  global_block) ||
  (pass_context == :prototype && !global_block) ||
  (pass_context == :target    && !global_block)
end
force_call(*args, &block) click to toggle source

When the CommandRecorder's commands are executed, they're rewritten to go through force_call, because the “effective set of commands” have already been determined by the CommandRecorder run.

# File lib/cell/ext/migration.rb, line 49
def force_call(*args, &block)
  saved, self.force_execution = self.force_execution, true
  send(*args, &block)
ensure
  self.force_execution = saved
end
global() { || ... } click to toggle source
# File lib/cell/ext/migration.rb, line 67
def global
  saved, self.global_block = self.global_block, true
  yield
ensure
  self.global_block = saved
end
with_context(context, search_path, exclusive: false) { || ... } click to toggle source
# File lib/cell/ext/migration.rb, line 56
def with_context(context, search_path, exclusive: false)
  Meta::with_schema(search_path, exclusive: exclusive) do
    begin
      saved, self.pass_context = self.pass_context, context
      yield
    ensure
      self.pass_context = saved
    end
  end
end