From cc2e43946fcaeeb34ea634c5b323d5b4a6347503 Mon Sep 17 00:00:00 2001 From: "qi.wang" Date: Tue, 26 May 2020 20:46:55 +0900 Subject: [PATCH] fix turntable for ar4013 --- lib/active_record/turntable/active_record_ext/fixtures.rb | 2 +- lib/active_record/turntable/base.rb | 8 ++++++-- lib/active_record/turntable/shard.rb | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/active_record/turntable/active_record_ext/fixtures.rb b/lib/active_record/turntable/active_record_ext/fixtures.rb index f3479a29..c32ec690 100644 --- a/lib/active_record/turntable/active_record_ext/fixtures.rb +++ b/lib/active_record/turntable/active_record_ext/fixtures.rb @@ -3,7 +3,7 @@ # require 'active_record/fixtures' module ActiveRecord - class Fixtures + class FixtureSet def self.create_fixtures(fixtures_directory, table_names, class_names = {}) table_names = [table_names].flatten.map { |n| n.to_s } table_names.each { |n| diff --git a/lib/active_record/turntable/base.rb b/lib/active_record/turntable/base.rb index 0339ee8a..89796994 100644 --- a/lib/active_record/turntable/base.rb +++ b/lib/active_record/turntable/base.rb @@ -62,7 +62,11 @@ def force_connect_all_shards! def turntable_replace_connection_pool ch = connection_handler cp = turntable_cluster.connection_proxy - if ActiveRecord::VERSION::STRING >= '3.2.0' + if ActiveRecord::VERSION::STRING >= '4.0.0' + proxy = PoolProxy.new(cp) + ch.send(:owner_to_pool)[name] = proxy + ch.send(:class_to_pool)[name] = proxy + elsif ActiveRecord::VERSION::STRING >= '3.2.0' ch.connection_pools[cp.spec] = PoolProxy.new(cp) ch.instance_variable_get(:@class_to_pool)[name] = ch.connection_pools[cp.spec] else @@ -77,7 +81,7 @@ def spec_for(config) raise "Please install the #{config['adapter']} adapter: `gem install activerecord-#{config['adapter']}-adapter` (#{e})" end adapter_method = "#{config['adapter']}_connection" - ActiveRecord::Base::ConnectionSpecification.new(config, adapter_method) + ActiveRecord::ConnectionAdapters::ConnectionSpecification.new(config, adapter_method) end def clear_all_connections! diff --git a/lib/active_record/turntable/shard.rb b/lib/active_record/turntable/shard.rb index f59e5b19..8f46acdc 100644 --- a/lib/active_record/turntable/shard.rb +++ b/lib/active_record/turntable/shard.rb @@ -42,7 +42,7 @@ def spec_for(config) raise "Please install the #{adapter} adapter: `gem install activerecord-#{adapter}-adapter` (#{e})" end adapter_method = "#{adapter}_connection" - ActiveRecord::Base::ConnectionSpecification.new(config, adapter_method) + ActiveRecord::ConnectionAdapters::ConnectionSpecification.new(config, adapter_method) end end end