From 38061eeab868f492ead6cc288de8d05a463f93bd Mon Sep 17 00:00:00 2001 From: Zack Mariscal Date: Fri, 2 Feb 2024 17:50:50 -0800 Subject: [PATCH 01/11] add trilogy and activerecord-trilogy-adapter to Gemfile --- Gemfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Gemfile b/Gemfile index 7a0c4d27..696a81b2 100644 --- a/Gemfile +++ b/Gemfile @@ -26,6 +26,8 @@ platforms :ruby do gem "sqlite3", "~> #{sqlite3_version}" # seamless_database_pool requires Ruby ~> 2.0 gem "seamless_database_pool", "~> 1.0.20" if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.0.0') + gem "trilogy" if version >= 6.1 + gem "activerecord-trilogy-adapter" if version >= 6.1 end platforms :jruby do From 5b97fd6cba9e9e0cd7997ede83a8a41ebdc24923 Mon Sep 17 00:00:00 2001 From: Zack Mariscal Date: Fri, 2 Feb 2024 17:53:03 -0800 Subject: [PATCH 02/11] add trilogy adapter and AR adapter that wrapse MysqlAdapter --- .../active_record/adapters/trilogy_adapter.rb | 8 ++++++++ lib/activerecord-import/adapters/trilogy_adapter.rb | 7 +++++++ 2 files changed, 15 insertions(+) create mode 100644 lib/activerecord-import/active_record/adapters/trilogy_adapter.rb create mode 100644 lib/activerecord-import/adapters/trilogy_adapter.rb diff --git a/lib/activerecord-import/active_record/adapters/trilogy_adapter.rb b/lib/activerecord-import/active_record/adapters/trilogy_adapter.rb new file mode 100644 index 00000000..201c2bb4 --- /dev/null +++ b/lib/activerecord-import/active_record/adapters/trilogy_adapter.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +require "active_record/connection_adapters/trilogy_adapter" +require "activerecord-import/adapters/trilogy_adapter" + +class ActiveRecord::ConnectionAdapters::TrilogyAdapter + include ActiveRecord::Import::TrilogyAdapter +end diff --git a/lib/activerecord-import/adapters/trilogy_adapter.rb b/lib/activerecord-import/adapters/trilogy_adapter.rb new file mode 100644 index 00000000..080c2db3 --- /dev/null +++ b/lib/activerecord-import/adapters/trilogy_adapter.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require "activerecord-import/adapters/mysql_adapter" + +module ActiveRecord::Import::TrilogyAdapter + include ActiveRecord::Import::MysqlAdapter +end From 35e6ab569f9e692aa0c3087e3188c94694ff4fb5 Mon Sep 17 00:00:00 2001 From: Zack Mariscal Date: Fri, 2 Feb 2024 17:53:58 -0800 Subject: [PATCH 03/11] add tests and add logic around where to include Trilogy adapter and connection --- .github/workflows/test.yaml | 17 +++++++++++++++++ Rakefile | 1 + test/adapters/trilogy.rb | 11 +++++++++++ test/database.yml.sample | 5 +++++ test/github/database.yml | 4 ++++ test/trilogy/import_test.rb | 7 +++++++ 6 files changed, 45 insertions(+) create mode 100644 test/adapters/trilogy.rb create mode 100644 test/trilogy/import_test.rb diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 2392eacc..29a945f6 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -16,6 +16,20 @@ jobs: --health-interval 10s --health-timeout 5s --health-retries 5 + mysql: + image: mysql:5.7 + ports: + - 3306:3306 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_USER: github + MYSQL_PASSWORD: github + MYSQL_DATABASE: activerecord_import_test + options: >- + --health-cmd "mysqladmin ping -h localhost" + --health-interval 10s + --health-timeout 5s + --health-retries 5 strategy: fail-fast: false matrix: @@ -110,6 +124,9 @@ jobs: run: | bundle exec rake test:spatialite bundle exec rake test:sqlite3 + - name: Run trilogy tests + if: ${{ matrix.env.AR_VERSION >= '7.0' }} + run: bundle exec rake test:trilogy lint: runs-on: ubuntu-latest env: diff --git a/Rakefile b/Rakefile index fedcf810..4c5b5c99 100644 --- a/Rakefile +++ b/Rakefile @@ -29,6 +29,7 @@ ADAPTERS = %w( sqlite3 spatialite seamless_database_pool + trilogy ).freeze ADAPTERS.each do |adapter| namespace :test do diff --git a/test/adapters/trilogy.rb b/test/adapters/trilogy.rb new file mode 100644 index 00000000..6eeee04a --- /dev/null +++ b/test/adapters/trilogy.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +# ensure we connect to the trilogy adapter +if ENV['AR_VERSION'].to_f >= 7.1 + ENV["ARE_DB"] = "trilogy" +else + require "activerecord-trilogy-adapter" + require "trilogy_adapter/connection" + ActiveRecord::Base.extend TrilogyAdapter::Connection + ENV["ARE_DB"] = "trilogy" +end diff --git a/test/database.yml.sample b/test/database.yml.sample index dc8d810a..34ee8ede 100644 --- a/test/database.yml.sample +++ b/test/database.yml.sample @@ -52,3 +52,8 @@ sqlite3: &sqlite3 spatialite: <<: *sqlite3 + +trilogy: + <<: *common + adapter: trilogy + host: mysql diff --git a/test/github/database.yml b/test/github/database.yml index a807c871..2d1fefe1 100644 --- a/test/github/database.yml +++ b/test/github/database.yml @@ -66,3 +66,7 @@ sqlite3: &sqlite3 spatialite: <<: *sqlite3 + +trilogy: + <<: *common + adapter: trilogy diff --git a/test/trilogy/import_test.rb b/test/trilogy/import_test.rb new file mode 100644 index 00000000..b256c2b7 --- /dev/null +++ b/test/trilogy/import_test.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require File.expand_path("#{File.dirname(__FILE__)}/../test_helper") +require File.expand_path("#{File.dirname(__FILE__)}/../support/assertions") +require File.expand_path("#{File.dirname(__FILE__)}/../support/mysql/import_examples") + +should_support_mysql_import_functionality From 7a27831664d226ad530e0bd63243ce60bb32c01a Mon Sep 17 00:00:00 2001 From: Zack Mariscal Date: Sat, 3 Feb 2024 08:25:07 -0800 Subject: [PATCH 04/11] restrict activerecord-trilogy-adapter to AR_VERSIONS < 7.1 as it's not needed --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 696a81b2..64467f2b 100644 --- a/Gemfile +++ b/Gemfile @@ -27,7 +27,7 @@ platforms :ruby do # seamless_database_pool requires Ruby ~> 2.0 gem "seamless_database_pool", "~> 1.0.20" if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.0.0') gem "trilogy" if version >= 6.1 - gem "activerecord-trilogy-adapter" if version >= 6.1 + gem "activerecord-trilogy-adapter" if version <= 7.0 end platforms :jruby do From 24ceeaeecd38745ede39a5b7f1dc4495ecbecb9a Mon Sep 17 00:00:00 2001 From: Zack Mariscal Date: Sat, 3 Feb 2024 08:49:39 -0800 Subject: [PATCH 05/11] refactor test trilogy file to extract ENV reference and simplify logic --- test/adapters/trilogy.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/adapters/trilogy.rb b/test/adapters/trilogy.rb index 6eeee04a..2f47249b 100644 --- a/test/adapters/trilogy.rb +++ b/test/adapters/trilogy.rb @@ -1,11 +1,9 @@ # frozen_string_literal: true -# ensure we connect to the trilogy adapter -if ENV['AR_VERSION'].to_f >= 7.1 - ENV["ARE_DB"] = "trilogy" -else +ENV["ARE_DB"] = "trilogy" + +if ENV['AR_VERSION'].to_f <= 7.0 require "activerecord-trilogy-adapter" require "trilogy_adapter/connection" ActiveRecord::Base.extend TrilogyAdapter::Connection - ENV["ARE_DB"] = "trilogy" end From 7109e15c9b93bc6d3e5bbbc79ba73eab0291dd7a Mon Sep 17 00:00:00 2001 From: Zack Mariscal Date: Sat, 3 Feb 2024 08:50:23 -0800 Subject: [PATCH 06/11] limit when activerecord-trilogy-adapter can be installed --- Gemfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 64467f2b..985e2222 100644 --- a/Gemfile +++ b/Gemfile @@ -27,7 +27,9 @@ platforms :ruby do # seamless_database_pool requires Ruby ~> 2.0 gem "seamless_database_pool", "~> 1.0.20" if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.0.0') gem "trilogy" if version >= 6.1 - gem "activerecord-trilogy-adapter" if version <= 7.0 + if version >= 6.0 && version <= 7.0 + gem "activerecord-trilogy-adapter" + end end platforms :jruby do From ada683774062379f44a74c86c4aabc88bba656d9 Mon Sep 17 00:00:00 2001 From: Zack Mariscal Date: Sat, 3 Feb 2024 09:56:29 -0800 Subject: [PATCH 07/11] specify latest version of rubygems --- .github/workflows/test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 29a945f6..c2993f70 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -95,6 +95,7 @@ jobs: with: ruby-version: ${{ matrix.ruby }} bundler-cache: true + rubygems: latest - name: Set up databases run: | sudo /etc/init.d/mysql start From cf0abcbd16704694633a7aaa1d2f2bb2f0ae4afe Mon Sep 17 00:00:00 2001 From: Zack Mariscal Date: Sat, 3 Feb 2024 14:34:31 -0800 Subject: [PATCH 08/11] set factory_bot version as it caused errors with older versions of Ruby https://github.com/thoughtbot/factory_bot/issues/1614 --- Gemfile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 985e2222..87a54e8b 100644 --- a/Gemfile +++ b/Gemfile @@ -41,7 +41,11 @@ platforms :jruby do end # Support libs -gem "factory_bot" +if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.0.0") + gem "factory_bot" +else + gem "factory_bot", "~> 6.2", "< 6.4.5" +end gem "timecop" gem "chronic" gem "mocha", "~> 2.1.0" From fddcaa2dd5634e9b4379bd77c5cd9438f87cd545 Mon Sep 17 00:00:00 2001 From: Zack Mariscal Date: Sat, 3 Feb 2024 18:56:49 -0800 Subject: [PATCH 09/11] scope changes only to run on ruby --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c2993f70..bfb06b3f 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -126,7 +126,7 @@ jobs: bundle exec rake test:spatialite bundle exec rake test:sqlite3 - name: Run trilogy tests - if: ${{ matrix.env.AR_VERSION >= '7.0' }} + if: ${{ matrix.env.AR_VERSION >= '7.0' && matrix.ruby != 'jruby' }} run: bundle exec rake test:trilogy lint: runs-on: ubuntu-latest From 3a3a22fea77b5dcc7564f770456e509754f49693 Mon Sep 17 00:00:00 2001 From: Zack Mariscal Date: Sat, 3 Feb 2024 20:08:18 -0800 Subject: [PATCH 10/11] lessen restrictions around factory_bot version --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 87a54e8b..af7abfc4 100644 --- a/Gemfile +++ b/Gemfile @@ -44,7 +44,7 @@ end if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.0.0") gem "factory_bot" else - gem "factory_bot", "~> 6.2", "< 6.4.5" + gem "factory_bot", "~> 5", "< 6.4.5" end gem "timecop" gem "chronic" From d0611bf4111eac631ddb6dc77f44d993612b44ff Mon Sep 17 00:00:00 2001 From: Zack Mariscal Date: Sat, 3 Feb 2024 21:42:45 -0800 Subject: [PATCH 11/11] bring trilogy gem version in line with what it actually supprots in AR --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index af7abfc4..4338f338 100644 --- a/Gemfile +++ b/Gemfile @@ -26,7 +26,7 @@ platforms :ruby do gem "sqlite3", "~> #{sqlite3_version}" # seamless_database_pool requires Ruby ~> 2.0 gem "seamless_database_pool", "~> 1.0.20" if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.0.0') - gem "trilogy" if version >= 6.1 + gem "trilogy" if version >= 6.0 if version >= 6.0 && version <= 7.0 gem "activerecord-trilogy-adapter" end