Skip to content

Commit

Permalink
Added support for Trilogy - closes #552
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Mar 26, 2024
1 parent f8235de commit 28a86e3
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ jobs:
with:
database: ahoy_test
- run: ADAPTER=mysql2 bundle exec rake test
- run: ADAPTER=trilogy bundle exec rake test

- uses: ankane/setup-mariadb@v1
with:
database: ahoy_test
- run: ADAPTER=mysql2 bundle exec rake test
- run: ADAPTER=trilogy bundle exec rake test

- uses: ankane/setup-mongodb@v1
- run: ADAPTER=mongoid bundle exec rake test
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 5.0.3 (unreleased)

- Added support for Trilogy

## 5.0.2 (2023-10-05)

- Excluded visits from Rails health check
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem "combustion"
gem "sqlite3"
gem "pg"
gem "mysql2"
gem "trilogy"
gem "mongoid"
gem "browser", "~> 2.0"
gem "user_agent_parser"
1 change: 1 addition & 0 deletions gemfiles/rails61.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem "combustion"
gem "sqlite3"
gem "pg"
gem "mysql2"
gem "activerecord-trilogy-adapter"
gem "mongoid", "~> 7"
gem "browser", "~> 2.0"
gem "user_agent_parser"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails70.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem "combustion"
gem "sqlite3"
gem "pg"
gem "mysql2"
gem "activerecord-trilogy-adapter"
gem "mongoid"
gem "browser", "~> 2.0"
gem "user_agent_parser"
Expand Down
4 changes: 2 additions & 2 deletions lib/ahoy/query_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def where_props(properties)
case adapter_name
when "mongoid"
where(properties.to_h { |k, v| ["properties.#{k}", v] })
when /mysql/
when /mysql|trilogy/
where("JSON_CONTAINS(properties, ?, '$') = 1", properties.to_json)
when /postgres|postgis/
case columns_hash["properties"].type
Expand Down Expand Up @@ -54,7 +54,7 @@ def group_prop(*props)
case adapter_name
when "mongoid"
raise "Adapter not supported: #{adapter_name}"
when /mysql/
when /mysql|trilogy/
props.each do |prop|
quoted_prop = connection.quote("$.#{prop}")
relation = relation.group("JSON_UNQUOTE(JSON_EXTRACT(properties, #{quoted_prop}))")
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/ahoy/activerecord_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def properties_type
case adapter
when /postg/i # postgres, postgis
"jsonb"
when /mysql/i
when /mysql|trilogy/i
"json"
else
"text"
Expand Down
2 changes: 1 addition & 1 deletion test/internal/config/database.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
test:
adapter: <%= ENV["ADAPTER"] || "sqlite3" %>
database: <%= ["postgresql", "mysql2"].include?(ENV["ADAPTER"]) ? "ahoy_test" : "db/combustion_test.sqlite" %>
database: <%= ["postgresql", "mysql2", "trilogy"].include?(ENV["ADAPTER"]) ? "ahoy_test" : "db/combustion_test.sqlite" %>
2 changes: 1 addition & 1 deletion test/query_methods/query_methods_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_relative "../test_helper"

case ENV["ADAPTER"]
when "mysql2"
when "mysql2", "trilogy"
require_relative "../support/mysql"
when "postgresql"
require_relative "../support/postgresql"
Expand Down
2 changes: 1 addition & 1 deletion test/query_methods_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_relative "test_helper"

case ENV["ADAPTER"]
when "mysql2"
when "mysql2", "trilogy"
require_relative "query_methods/mysql_json_test"
require_relative "query_methods/mysql_text_test"
when "postgresql"
Expand Down
4 changes: 2 additions & 2 deletions test/support/query_methods_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ def sqlite?
end

def mysql?
self.class.name =~ /mysql/i && !model.connection.try(:mariadb?)
self.class.name =~ /mysql|trilogy/i && !model.connection.try(:mariadb?)
end

def mariadb?
self.class.name =~ /mysql/i && model.connection.try(:mariadb?)
self.class.name =~ /mysql|trilogy/i && model.connection.try(:mariadb?)
end

def hstore?
Expand Down
4 changes: 4 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
frameworks << :active_record
end

if ENV["ADAPTER"] == "trilogy"
Combustion::Database::Reset::OPERATOR_PATTERNS[Combustion::Databases::MySQL] << /trilogy/
end

Combustion.path = "test/internal"
Combustion.initialize!(*frameworks) do
config.load_defaults Rails::VERSION::STRING.to_f
Expand Down

0 comments on commit 28a86e3

Please sign in to comment.