From 9c27af60f9d5d8623b1c0cb4b71363c94745b096 Mon Sep 17 00:00:00 2001 From: fumihumi Date: Tue, 24 Oct 2023 19:15:15 +0900 Subject: [PATCH 1/4] Solved AS::LogSubscriber#color DEPRECATION WARNING * ActiveSupport::LogSubscriber#color bolding options was changed in rails 7.1.0 ref: rails/rails#45976 * original commit: https://github.com/aktsk/octoball/pull/8 --- lib/octoball/log_subscriber.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/octoball/log_subscriber.rb b/lib/octoball/log_subscriber.rb index 4c5b998..b30dfa3 100644 --- a/lib/octoball/log_subscriber.rb +++ b/lib/octoball/log_subscriber.rb @@ -12,7 +12,11 @@ def sql(event) private def debug(progname = nil, &block) - conn = current_shard ? color("[Shard: #{current_shard}]", ActiveSupport::LogSubscriber::GREEN, true) : '' + if ActiveRecord.gem_version >= Gem::Version.new('7.1.0') + conn = current_shard ? color("[Shard: #{current_shard}]", ActiveSupport::LogSubscriber::GREEN, bold: true) : '' + else + conn = current_shard ? color("[Shard: #{current_shard}]", ActiveSupport::LogSubscriber::GREEN, true) : '' + end super(conn + progname.to_s, &block) end end From a80d8a3e4e85308aa0193976cb335835c50c4e4d Mon Sep 17 00:00:00 2001 From: fumihumi Date: Wed, 25 Oct 2023 11:24:49 +0900 Subject: [PATCH 2/4] fix default_shard spec * ref: https://github.com/rails/rails/pull/48353/files * ActiveRecord has been modified to use default_shards estimation with keys.first of connects_to hash --- spec/octoball/model_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/octoball/model_spec.rb b/spec/octoball/model_spec.rb index 3da3763..3992c1f 100644 --- a/spec/octoball/model_spec.rb +++ b/spec/octoball/model_spec.rb @@ -123,7 +123,7 @@ it 'should clean #current_shard from proxy when using execute' do User.using(:canada).connection.execute('select * from users limit 1;') - expect(User.connection.current_shard).to eq(:default) + expect(User.connection.current_shard).to eq(:master) end it 'should allow scoping dynamically' do @@ -264,7 +264,7 @@ describe 'AR basic methods' do it 'connects_to' do - expect(CustomConnection.connection.current_database).to eq('octoball_shard_2') + expect(CustomConnection.connection.current_database).to eq('octoball_shard_3') end it 'reuses parent model connection' do @@ -590,7 +590,7 @@ describe 'custom connection' do context 'by default' do it 'with plain call should use custom connection' do - expect(CustomConnection.connection.current_database).to eq('octoball_shard_2') + expect(CustomConnection.connection.current_database).to eq('octoball_shard_3') end it 'should use model-specific shard' do From 965042cfdcd20499127cbe4a7ae71a0f84765aeb Mon Sep 17 00:00:00 2001 From: fumihumi Date: Wed, 25 Oct 2023 11:53:05 +0900 Subject: [PATCH 3/4] fix swap_connection_handler method definition swap_connection_handler method has been removed since rails 7.1 ref: https://github.com/rails/rails/commit/1bbaf0d581e5b48653af9b614da7d30e64d48fa8 --- lib/octoball/connection_handling.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/octoball/connection_handling.rb b/lib/octoball/connection_handling.rb index 549d997..8b62162 100644 --- a/lib/octoball/connection_handling.rb +++ b/lib/octoball/connection_handling.rb @@ -4,13 +4,15 @@ class Octoball module ConnectionHandlingAvoidAutoLoadProxy private - def swap_connection_handler(handler, &blk) - old_handler, ActiveRecord::Base.connection_handler = ActiveRecord::Base.connection_handler, handler - return_value = yield - return_value.load if !return_value.respond_to?(:ar_relation) && return_value.is_a?(ActiveRecord::Relation) - return_value - ensure - ActiveRecord::Base.connection_handler = old_handler + if ActiveRecord.gem_version < Gem::Version.new('7.1.0') + def swap_connection_handler(handler, &blk) + old_handler, ActiveRecord::Base.connection_handler = ActiveRecord::Base.connection_handler, handler + return_value = yield + return_value.load if !return_value.respond_to?(:ar_relation) && return_value.is_a?(ActiveRecord::Relation) + return_value + ensure + ActiveRecord::Base.connection_handler = old_handler + end end end From dc8f138e165cdb21a91dc771ef9d2a29d088df4f Mon Sep 17 00:00:00 2001 From: fumihumi Date: Wed, 25 Oct 2023 12:00:22 +0900 Subject: [PATCH 4/4] fix CI gem version --- .github/Gemfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/Gemfile b/.github/Gemfile index ab52e9a..c06a9c2 100644 --- a/.github/Gemfile +++ b/.github/Gemfile @@ -1,8 +1,8 @@ source 'https://rubygems.org' if RUBY_VERSION < '3.0' - gem 'activerecord', '~> 6.1.0' - gem 'activesupport', '~> 6.1.0' + gem 'activerecord', '~> 7.1.1' + gem 'activesupport', '~> 7.1.1' end gemspec :path => '../'