Skip to content

Commit

Permalink
Allow not delete triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
perryism committed Jan 26, 2018
1 parent 28b35e5 commit d605c73
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/lhm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def sync_table(table_name, sync_table, options = {}, &block)
origin = Table.parse(table_name, connection)
invoker = Invoker.new(origin, connection)
block.call(invoker.migrator)
options.merge!({disable_switcher: true})
options.merge!({disable_switcher: true, delete_trigger_after: false})
invoker.run(options)
ensure
Lhm::Table.naming_strategy = nil
Expand Down
6 changes: 4 additions & 2 deletions lib/lhm/entangler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ class Entangler
include Command
include SqlHelper

attr_reader :connection
attr_reader :connection, :delete_trigger_after

# Creates entanglement between two tables. All creates, updates and deletes
# to origin will be repeated on the destination table.
def initialize(migration, connection = nil)
def initialize(migration, connection = nil, delete_trigger_after = true)
@intersection = migration.intersection
@origin = migration.origin
@destination = migration.destination
@connection = connection
@delete_trigger_after = delete_trigger_after
end

def entangle
Expand Down Expand Up @@ -85,6 +86,7 @@ def before
end

def after
return unless @delete_trigger_after
untangle.each do |stmt|
@connection.execute(tagged(stmt))
end
Expand Down
2 changes: 1 addition & 1 deletion lib/lhm/invoker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def run(options = {})
set_session_lock_wait_timeouts
migration = @migrator.run

Entangler.new(migration, @connection).run do
Entangler.new(migration, @connection, options[:delete_trigger_after] && true).run do
Chunker.new(migration, @connection, options).run
if options[:disable_switcher]
Lhm.logger.debug 'switcher is disabled'
Expand Down

0 comments on commit d605c73

Please sign in to comment.