Class: Lhm::AtomicSwitcher
- Inherits:
-
Object
- Object
- Lhm::AtomicSwitcher
- 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?.
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.
- #statements ⇒ Object
- #validate ⇒ Object
Methods included from SqlHelper
#annotation, #idx_name, #idx_spec, #sql, #table?, #update, #version_string
Methods included from Command
Constructor Details
#initialize(migration, connection = nil) ⇒ AtomicSwitcher
Returns a new instance of AtomicSwitcher.
20 21 22 23 24 25 |
# File 'lib/lhm/atomic_switcher.rb', line 20 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.
18 19 20 |
# File 'lib/lhm/atomic_switcher.rb', line 18 def connection @connection end |
Instance Method Details
#atomic_switch ⇒ Object
31 32 33 34 35 36 |
# File 'lib/lhm/atomic_switcher.rb', line 31 def atomic_switch [ "rename table `#{ @origin.name }` to `#{ @migration.archive_name }`, " + "`#{ @destination.name }` to `#{ @origin.name }`" ] end |
#statements ⇒ Object
27 28 29 |
# File 'lib/lhm/atomic_switcher.rb', line 27 def statements atomic_switch end |
#validate ⇒ Object
38 39 40 41 42 |
# File 'lib/lhm/atomic_switcher.rb', line 38 def validate unless table?(@origin.name) && table?(@destination.name) error "`#{ @origin.name }` and `#{ @destination.name }` must exist" end end |