Skip to content

Commit

Permalink
Add support for mysql2rgeo DB adapter (#121)
Browse files Browse the repository at this point in the history
Hi, 
I have been using hair_trigger for some time, and now I need to start
using mysql2rgeo DB adapter to handle some spatial data.
[mysql2rgeo](https://github.com/stadia/activerecord-mysql2rgeo-adapter)
extends basic myslq2 adapter with spatial functionalities.

As I would like to continue using hair_trigger I posted da PR to add
support for mysql2rgeo adapter.
I hope you will consider this addition and let me know if anything needs
to be modified.

All the best
Jan

Co-authored-by: Jon Jensen <[email protected]>
  • Loading branch information
JanZivkovicio and jenseng authored Sep 4, 2024
1 parent f44787c commit 5f76c72
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/hair_trigger/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions lib/hair_trigger/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions spec/adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down

0 comments on commit 5f76c72

Please sign in to comment.