Class: Lhm::Invoker

Inherits:
Object
  • Object
show all
Includes:
SqlHelper
Defined in:
lib/lhm/invoker.rb

Overview

Copies an origin table to an altered destination table. Live activity is synchronized into the destination table using triggers.

Once the origin and destination tables have converged, origin is archived and replaced by destination.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SqlHelper

#annotation, #idx_name, #idx_spec, #sql, #table?, #update, #version_string

Constructor Details

#initialize(origin, connection) ⇒ Invoker

Returns a new instance of Invoker.



21
22
23
24
# File 'lib/lhm/invoker.rb', line 21

def initialize(origin, connection)
  @connection = connection
  @migrator = Migrator.new(origin, connection)
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



19
20
21
# File 'lib/lhm/invoker.rb', line 19

def connection
  @connection
end

#migratorObject (readonly)

Returns the value of attribute migrator.



19
20
21
# File 'lib/lhm/invoker.rb', line 19

def migrator
  @migrator
end

Instance Method Details

#run(options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/lhm/invoker.rb', line 26

def run(options = {})
  if !options.include?(:atomic_switch)
    if supports_atomic_switch?
      options[:atomic_switch] = true
    else
      raise Error.new(
        "Using mysql #{version_string}. You must explicitly set " +
        "options[:atomic_switch] (re SqlHelper#supports_atomic_switch?)")
    end
  end

  migration = @migrator.run

  Entangler.new(migration, @connection).run do
    Chunker.new(migration, @connection, options).run
    if options[:atomic_switch]
      AtomicSwitcher.new(migration, @connection).run
    else
      LockedSwitcher.new(migration, @connection).run
    end
  end
end