From f0ddd2be68e0221f47e7145ffc7f3aaf6d1e4c97 Mon Sep 17 00:00:00 2001 From: Aidan Date: Thu, 10 Oct 2024 23:18:04 -0400 Subject: [PATCH 1/5] test both activerecord versions --- .github/workflows/test-release.yml | 8 ++++++-- Gemfile | 14 ++++++++++++++ Taskfile.yml | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-release.yml b/.github/workflows/test-release.yml index ba9d7b8..524e496 100644 --- a/.github/workflows/test-release.yml +++ b/.github/workflows/test-release.yml @@ -23,6 +23,10 @@ jobs: - "2.7" - "3.1" - "3.2" + - "3.3" + activerecord: + - "7.1" + - "7.2" steps: - uses: actions/checkout@v3 - uses: ruby/setup-ruby@v1 @@ -42,7 +46,7 @@ jobs: - uses: actions/checkout@v3 - uses: ruby/setup-ruby@v1 with: - ruby-version: "3.2" + ruby-version: "3.3" # The kickstarter/actions/setup-rubygems action is not available # because this is a public repo - name: setup-rubygems @@ -53,5 +57,5 @@ jobs: :rubygems_api_key: ${{ secrets.RUBYGEMS_API_KEY }} YAML chmod 0600 ~/.gem/credentials - - run: bundle install + - run: ACTIVE_RECORD_VERSION=${{ matrix.activerecord }} bundle install - run: bundle exec rake release diff --git a/Gemfile b/Gemfile index 3be9c3c..1c249f6 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,16 @@ source "https://rubygems.org" gemspec + +group :development do + # This allows us to easily switch between different versions of ActiveRecord. + # To use this in local dev, you can do: + # ``` + # rm Gemfile.lock + # ACTIVE_RECORD_VERSION="7.1" bundle install + # ``` + active_record_version = ENV.fetch("ACTIVE_RECORD_VERSION", nil) + gem "activerecord", "~> #{active_record_version}.0" if active_record_version&.length&.positive? + + # Just helping out the bundler resolver: + gem "rails", "> 6.0" +end diff --git a/Taskfile.yml b/Taskfile.yml index 160cb8e..390a7d7 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -6,7 +6,7 @@ dotenv: - .env vars: - RUBY_VERSION: 3.2.2 + RUBY_VERSION: 3.3.5 tasks: init: From fab842e13481d2661fe7f667b03e85274018932e Mon Sep 17 00:00:00 2001 From: Aidan Date: Sun, 13 Oct 2024 22:19:10 -0400 Subject: [PATCH 2/5] setup focus in rspec --- spec/spec_helper.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 68b8a4d..54810e3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -50,4 +50,7 @@ def reset_proxy(proxy) c.mock_with :rspec do |c| c.syntax = [:expect, :should] end + + c.filter_run focus: true + c.run_all_when_everything_filtered = true end From 1d82421b37b9036b0a43d8285e73bfae52ee1814 Mon Sep 17 00:00:00 2001 From: Aidan Date: Sun, 13 Oct 2024 21:46:19 -0400 Subject: [PATCH 3/5] update QueryCache tests for 7.2 We need to accomodate the changes in this commit: https://github.com/rails/rails/commit/85742ce529b028812066cd6070e7de2ff3d44bc8 `#query_cache` used to return a `Hash`, but it now returns a custom class. Fortunately, both `Hash` and this custom class implement a `#size` method which works the same as doing `keys.size`. --- spec/query_cache_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/query_cache_spec.rb b/spec/query_cache_spec.rb index 51135d8..df2457d 100644 --- a/spec/query_cache_spec.rb +++ b/spec/query_cache_spec.rb @@ -22,7 +22,7 @@ @default_replica2.should_not_receive(:select_all) @leader.should_not_receive(:select_all) 3.times { @proxy.select_all(@sql) } - @leader.query_cache.keys.size.should == 1 + @leader.query_cache.size.should == 1 end end @@ -38,9 +38,9 @@ 5.times do |i| @proxy.select_all(@sql) @proxy.select_all(@sql) - @leader.query_cache.keys.size.should == 1 + @leader.query_cache.size.should == 1 @proxy.send(meths[i], '') - @leader.query_cache.keys.size.should == 0 + @leader.query_cache.size.should == 0 end end end From 590abfed9e41fbbba776f8427e2c3858f6757e65 Mon Sep 17 00:00:00 2001 From: Aidan Date: Sun, 13 Oct 2024 22:57:51 -0400 Subject: [PATCH 4/5] add `with_connection_proxy` method `ActiveRecord::Base` now has the `with_connection` method, which is like the old `connection` method on `ActiveRecord::Base` but it yields the connection to a block instead of returning it: https://github.com/rails/rails/commit/22f41a1b40eb3ff5b94c8db4495ec5c93b513685 This new method is now used for transactions, so in order for transactions to work we need to implement an equivalent in Replica Pools. --- lib/replica_pools/active_record_extensions.rb | 4 ++++ lib/replica_pools/hijack.rb | 1 + 2 files changed, 5 insertions(+) diff --git a/lib/replica_pools/active_record_extensions.rb b/lib/replica_pools/active_record_extensions.rb index ebd58bb..1513628 100644 --- a/lib/replica_pools/active_record_extensions.rb +++ b/lib/replica_pools/active_record_extensions.rb @@ -17,6 +17,10 @@ def connection_proxy ReplicaPools.proxy end + def with_connection_proxy + yield ReplicaPools.proxy + end + # Make sure transactions run on leader # Even if they're initiated from ActiveRecord::Base # (which doesn't have our hijack). diff --git a/lib/replica_pools/hijack.rb b/lib/replica_pools/hijack.rb index 8bfe9de..1d92f04 100644 --- a/lib/replica_pools/hijack.rb +++ b/lib/replica_pools/hijack.rb @@ -18,6 +18,7 @@ def inherited(child) def hijack_connection class << self alias_method :connection, :connection_proxy + alias_method :with_connection, :with_connection_proxy end end end From 82a9d4506a6e12c123a427e3f87fe796587e24a0 Mon Sep 17 00:00:00 2001 From: Aidan Date: Tue, 15 Oct 2024 10:00:16 -0400 Subject: [PATCH 5/5] bump checkout action version --- .github/workflows/test-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-release.yml b/.github/workflows/test-release.yml index 524e496..d7cebae 100644 --- a/.github/workflows/test-release.yml +++ b/.github/workflows/test-release.yml @@ -28,7 +28,7 @@ jobs: - "7.1" - "7.2" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }}