diff --git a/README.md b/README.md index 38e4e291..a0352b1d 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,11 @@ end to prevent accidental data loss. After successful or failed LHM migrations, these leftover tables must be cleaned up. +**Note:** When developing locally or running tests, LHM runs 'inline' by default, meaning that the +extra table is not used and the original table is not replaced. If this behavior is not desirable +for your project, you can disable it by setting `Lhm.disallow_inline!` in the appropriate +environment file or initializer. + ### Usage with ProxySQL LHM can recover from connection loss. However, when used in conjunction with ProxySQL, there are multiple ways that connection loss could induce data loss (if triggered by a failover). Therefore it will perform additional checks to diff --git a/lib/lhm.rb b/lib/lhm.rb index a09e5257..654cd9e1 100644 --- a/lib/lhm.rb +++ b/lib/lhm.rb @@ -116,6 +116,18 @@ def self.logger end end + @@disallow_inline = false + + # Use to control the inline-execution of Lhm migrations - by default migrations are inlined + # in test and development environments, and in some cases that's not desireable. + def self.disallow_inline! + @@disallow_inline = true + end + + def self.inline_allowed? + !@@disallow_inline + end + private def drop_tables_and_triggers(run = false, triggers, tables) diff --git a/lib/lhm/railtie.rb b/lib/lhm/railtie.rb index 2cdcb1eb..fcfb656f 100644 --- a/lib/lhm/railtie.rb +++ b/lib/lhm/railtie.rb @@ -2,7 +2,7 @@ module Lhm class Railtie < Rails::Railtie initializer "lhm.test_setup" do if Rails.env.test? || Rails.env.development? - Lhm.execute_inline! + Lhm.execute_inline! if Lhm.inline_allowed? end end end