Skip to content

Commit

Permalink
Support trilogy as mysql adapter (#115)
Browse files Browse the repository at this point in the history
Add support for trilogy adapter 

https://github.com/trilogy-libraries/trilogy
https://github.com/trilogy-libraries/activerecord-trilogy-adapter

Trilogy adapter is now supported as a native mysql adapter in Rails 7.1

Co-authored-by: Alexandre Overtus <[email protected]>
  • Loading branch information
aovertus and aovertus authored Jan 2, 2024
1 parent 735e816 commit 4d30700
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
appraise "activerecord-6.0" do
gem "activerecord", "~> 6.0.0"
gem "activerecord-trilogy-adapter", "~> 3.0.0"
gem "mysql2", "~> 0.4.10"
gem "pg", ">= 0.18", "< 2.0"
gem "sqlite3", "~> 1.4.0"
end

appraise "activerecord-6.1" do
gem "activerecord", "~> 6.1.0"
gem "activerecord-trilogy-adapter", "~> 3.0.0"
gem "mysql2", "~> 0.5"
gem "pg", ">= 0.18", "< 2.0"
gem "sqlite3", "~> 1.4.0"
end

appraise "activerecord-7.0" do
gem "activerecord", "~> 7.0.0"
gem "activerecord-trilogy-adapter", "~> 3.0.0"
gem "mysql2", "~> 0.5"
gem "pg", ">= 0.18", "< 2.0"
gem "sqlite3", "~> 1.4.0"
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## 1.0.x
## 1.1.x

## 1.1.0

- Add support for trilogy adapter ([PR 115](https://github.com/jenseng/hair_trigger/pulls)

### 1.0.0

Expand Down
1 change: 1 addition & 0 deletions gemfiles/activerecord_6.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
source "https://rubygems.org"

gem "activerecord", "~> 6.0.0"
gem "activerecord-trilogy-adapter"
gem "mysql2", "~> 0.4.10"
gem "pg", ">= 0.18", "< 2.0"
gem "sqlite3", "~> 1.4.0"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/activerecord_6.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
source "https://rubygems.org"

gem "activerecord", "~> 6.1.0"
gem "activerecord-trilogy-adapter"
gem "mysql2", "~> 0.5"
gem "pg", ">= 0.18", "< 2.0"
gem "sqlite3", "~> 1.4.0"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/activerecord_7.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
source "https://rubygems.org"

gem "activerecord", "~> 7.0.0"
gem "activerecord-trilogy-adapter", "~> 3.0.0"
gem "mysql2", "~> 0.5"
gem "pg", ">= 0.18", "< 2.0"
gem "sqlite3", "~> 1.4.0"
Expand Down
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
when :mysql, :trilogy
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 == :mysql || adapter_name == :trilogy
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
when :mysql, :trilogy
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
when :sqlite, :mysql, :trilogy
"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 @@ -55,6 +55,11 @@
it_behaves_like "mysql"
end if ADAPTERS.include? :mysql2

context "trilogy" do
let(:adapter) { :trilogy }
it_behaves_like "mysql"
end if ADAPTERS.include? :trilogy

context "postgresql" do
let(:adapter) { :postgresql }

Expand Down

0 comments on commit 4d30700

Please sign in to comment.