Sha256: b5d8475aa6ec89e7b19b086c266480514bbf6e2c65a7c38740349e9bc6d19dfd
Contents?: true
Size: 1.27 KB
Versions: 3
Compression:
Stored size: 1.27 KB
Contents
# Copyright (c) 2011 - 2013, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias # Schmidt require 'lhm/command' require 'lhm/migration' require 'lhm/sql_retry' module Lhm # Switches origin with destination table using an atomic rename. # # It should only be used if the MySQL server version is not affected by the # bin log affecting bug #39675. This can be verified using # Lhm::SqlHelper.supports_atomic_switch?. class AtomicSwitcher include Command attr_reader :connection def initialize(migration, connection = nil, options={}) @migration = migration @connection = connection @origin = migration.origin @destination = migration.destination @retry_options = options[:retriable] || {} end def atomic_switch "rename table `#{ @origin.name }` to `#{ @migration.archive_name }`, " \ "`#{ @destination.name }` to `#{ @origin.name }`" end def validate unless @connection.data_source_exists?(@origin.name) && @connection.data_source_exists?(@destination.name) error "`#{ @origin.name }` and `#{ @destination.name }` must exist" end end private def execute @connection.execute(atomic_switch, should_retry: true, retry_options: @retry_options) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
lhm-shopify-3.5.3 | lib/lhm/atomic_switcher.rb |
lhm-shopify-3.5.2 | lib/lhm/atomic_switcher.rb |
lhm-shopify-3.5.1 | lib/lhm/atomic_switcher.rb |