From c31cc0d24dd55fab2f1522a1f2e8fe1e83e94e09 Mon Sep 17 00:00:00 2001 From: JanZivkovicio <114908542+JanZivkovicio@users.noreply.github.com> Date: Wed, 14 Feb 2024 14:54:10 +0100 Subject: [PATCH] Add support for mysql2rgeo DB adapter --- lib/hair_trigger/adapter.rb | 2 +- lib/hair_trigger/builder.rb | 6 +++--- spec/adapter_spec.rb | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/hair_trigger/adapter.rb b/lib/hair_trigger/adapter.rb index 1b9e594..60cbd73 100644 --- a/lib/hair_trigger/adapter.rb +++ b/lib/hair_trigger/adapter.rb @@ -31,7 +31,7 @@ def triggers(options = {}) select_rows("SELECT name, sql FROM sqlite_master WHERE type = 'trigger' #{name_clause ? " AND name " + name_clause : ""}").each do |(name, definition)| triggers[name] = quote_table_name_in_trigger(definition) + ";\n" end - when :mysql, :trilogy + when :mysql, :trilogy, :mysql2rgeo select_rows("SHOW TRIGGERS").each do |(name, event, table, actions, timing, created, sql_mode, definer)| definer = normalize_mysql_definer(definer) next if options[:only] && !options[:only].include?(name) diff --git a/lib/hair_trigger/builder.rb b/lib/hair_trigger/builder.rb index c8bbe64..818750f 100644 --- a/lib/hair_trigger/builder.rb +++ b/lib/hair_trigger/builder.rb @@ -162,7 +162,7 @@ def set_#{method}(*args, &block) chainable_methods :name, :on, :for_each, :before, :after, :where, :security, :timing, :events, :all, :nowrap, :of, :declare def create_grouped_trigger? - adapter_name == :mysql || adapter_name == :trilogy + adapter_name == :mysql || adapter_name == :trilogy || adapter_name == :mysql2rgeo end def prepare! @@ -224,7 +224,7 @@ def generate(validate = true) [case adapter_name when :sqlite generate_trigger_sqlite - when :mysql, :trilogy + when :mysql, :trilogy, :mysql2rgeo generate_trigger_mysql when :postgresql, :postgis generate_trigger_postgresql @@ -407,7 +407,7 @@ def supports_of? def generate_drop_trigger case adapter_name - when :sqlite, :mysql, :trilogy + when :sqlite, :mysql, :trilogy, :mysql2rgeo "DROP TRIGGER IF EXISTS #{prepared_name};\n" when :postgresql, :postgis "DROP TRIGGER IF EXISTS #{prepared_name} ON #{adapter.quote_table_name(options[:table])};\nDROP FUNCTION IF EXISTS #{adapter.quote_table_name(prepared_name)}();\n" diff --git a/spec/adapter_spec.rb b/spec/adapter_spec.rb index b4c2db6..a97d9f4 100644 --- a/spec/adapter_spec.rb +++ b/spec/adapter_spec.rb @@ -60,6 +60,11 @@ it_behaves_like "mysql" end if ADAPTERS.include? :trilogy + context "mysql2rgeo" do + let(:adapter) { :mysql2rgeo } + it_behaves_like "mysql" + end if ADAPTERS.include? :mysql2rgeo + context "postgresql" do let(:adapter) { :postgresql }