Class: Lhm::AtomicSwitcher
- Inherits:
-
Object
- Object
- Lhm::AtomicSwitcher
- Includes:
- Command
- Defined in:
- lib/lhm/atomic_switcher.rb
Overview
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?.
Constant Summary collapse
- LOG_PREFIX =
"AtomicSwitcher"
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #atomic_switch ⇒ Object
-
#initialize(migration, connection = nil) ⇒ AtomicSwitcher
constructor
A new instance of AtomicSwitcher.
- #validate ⇒ Object
Methods included from Command
Constructor Details
#initialize(migration, connection = nil) ⇒ AtomicSwitcher
Returns a new instance of AtomicSwitcher.
21 22 23 24 25 26 |
# File 'lib/lhm/atomic_switcher.rb', line 21 def initialize(migration, connection = nil) @migration = migration @connection = connection @origin = migration.origin @destination = migration.destination end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
17 18 19 |
# File 'lib/lhm/atomic_switcher.rb', line 17 def connection @connection end |
Instance Method Details
#atomic_switch ⇒ Object
28 29 30 31 |
# File 'lib/lhm/atomic_switcher.rb', line 28 def atomic_switch "RENAME TABLE `#{ @origin.name }` TO `#{ @migration.archive_name }`, " \ "`#{ @destination.name }` TO `#{ @origin.name }`" end |
#validate ⇒ Object
33 34 35 36 37 38 |
# File 'lib/lhm/atomic_switcher.rb', line 33 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 |