From 28a86e3541f16cb5abe4d2e504def256cc64fdfa Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Tue, 26 Mar 2024 09:17:50 -0700 Subject: [PATCH] Added support for Trilogy - closes #552 --- .github/workflows/build.yml | 2 ++ CHANGELOG.md | 4 ++++ Gemfile | 1 + gemfiles/rails61.gemfile | 1 + gemfiles/rails70.gemfile | 1 + lib/ahoy/query_methods.rb | 4 ++-- lib/generators/ahoy/activerecord_generator.rb | 2 +- test/internal/config/database.yml | 2 +- test/query_methods/query_methods_helper.rb | 2 +- test/query_methods_test.rb | 2 +- test/support/query_methods_test.rb | 4 ++-- test/test_helper.rb | 4 ++++ 12 files changed, 21 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 20964d9e..aec527c4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index f1f8299a..c18c1352 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.0.3 (unreleased) + +- Added support for Trilogy + ## 5.0.2 (2023-10-05) - Excluded visits from Rails health check diff --git a/Gemfile b/Gemfile index 538677fd..f9878eb2 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,7 @@ gem "combustion" gem "sqlite3" gem "pg" gem "mysql2" +gem "trilogy" gem "mongoid" gem "browser", "~> 2.0" gem "user_agent_parser" diff --git a/gemfiles/rails61.gemfile b/gemfiles/rails61.gemfile index dc6810c6..67d2ecdd 100644 --- a/gemfiles/rails61.gemfile +++ b/gemfiles/rails61.gemfile @@ -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" diff --git a/gemfiles/rails70.gemfile b/gemfiles/rails70.gemfile index cbb6e2c9..747696f7 100644 --- a/gemfiles/rails70.gemfile +++ b/gemfiles/rails70.gemfile @@ -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" diff --git a/lib/ahoy/query_methods.rb b/lib/ahoy/query_methods.rb index 324c87eb..a17f4a06 100644 --- a/lib/ahoy/query_methods.rb +++ b/lib/ahoy/query_methods.rb @@ -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 @@ -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}))") diff --git a/lib/generators/ahoy/activerecord_generator.rb b/lib/generators/ahoy/activerecord_generator.rb index 91419b49..2838ab06 100644 --- a/lib/generators/ahoy/activerecord_generator.rb +++ b/lib/generators/ahoy/activerecord_generator.rb @@ -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" diff --git a/test/internal/config/database.yml b/test/internal/config/database.yml index 7444180d..59b6e412 100644 --- a/test/internal/config/database.yml +++ b/test/internal/config/database.yml @@ -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" %> diff --git a/test/query_methods/query_methods_helper.rb b/test/query_methods/query_methods_helper.rb index 3cc68ce2..582f9302 100644 --- a/test/query_methods/query_methods_helper.rb +++ b/test/query_methods/query_methods_helper.rb @@ -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" diff --git a/test/query_methods_test.rb b/test/query_methods_test.rb index df05a3a9..937364a2 100644 --- a/test/query_methods_test.rb +++ b/test/query_methods_test.rb @@ -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" diff --git a/test/support/query_methods_test.rb b/test/support/query_methods_test.rb index 583e3a3f..251ccf74 100644 --- a/test/support/query_methods_test.rb +++ b/test/support/query_methods_test.rb @@ -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? diff --git a/test/test_helper.rb b/test/test_helper.rb index 8a3dc2f0..833b7042 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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