From 8e306db6c5f39dc42578d579b86feca4a97d6819 Mon Sep 17 00:00:00 2001 From: Eric Mueller Date: Tue, 6 Dec 2022 15:02:55 -0500 Subject: [PATCH 1/3] add Lhm.disallow_inline! and Lhm.inline_allowed? methods for configuration default to 'allowed', since that matches existing behavior --- lib/lhm.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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) From 28ee94f3984126346dd8a3e51a098d97bf6b58eb Mon Sep 17 00:00:00 2001 From: Eric Mueller Date: Tue, 6 Dec 2022 15:03:21 -0500 Subject: [PATCH 2/3] update the railtie to check Lhm.inline_allowed? before inlining migrations --- lib/lhm/railtie.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 2714c3833882d6e784ae94259b38290090ee0e3a Mon Sep 17 00:00:00 2001 From: Eric Mueller Date: Tue, 6 Dec 2022 15:03:37 -0500 Subject: [PATCH 3/3] add a note to the readme describing how to use the new configuration option --- README.md | 5 +++++ 1 file changed, 5 insertions(+) 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