diff --git a/lib/octopus.rb b/lib/octopus.rb index ffea3f78..cf22ad05 100644 --- a/lib/octopus.rb +++ b/lib/octopus.rb @@ -101,7 +101,7 @@ def self.rails42? def self.rails50? ActiveRecord::VERSION::MAJOR == 5 && ActiveRecord::VERSION::MINOR == 0 end - + def self.atleast_rails50? ActiveRecord::VERSION::MAJOR >= 5 end @@ -122,6 +122,10 @@ def self.atleast_rails52? ActiveRecord::VERSION::MAJOR > 5 || (ActiveRecord::VERSION::MAJOR == 5 && ActiveRecord::VERSION::MINOR > 1) end + def self.atleast_rails61? + ActiveRecord::VERSION::MAJOR > 6 || (ActiveRecord::VERSION::MAJOR == 6 && ActiveRecord::VERSION::MINOR >= 1) + end + attr_writer :logger def self.logger diff --git a/lib/octopus/collection_association.rb b/lib/octopus/collection_association.rb index 6713271a..87345618 100644 --- a/lib/octopus/collection_association.rb +++ b/lib/octopus/collection_association.rb @@ -1,7 +1,7 @@ module Octopus module CollectionAssociation def self.included(base) - if Octopus.rails51? || Octopus.rails52? + if Octopus.rails51? || Octopus.rails52? || Octopus.atleast_rails61? base.sharded_methods :reader, :writer, :ids_reader, :ids_writer, :create, :create!, :build, :include?, :load_target, :reload, :size, :select diff --git a/lib/octopus/proxy_config.rb b/lib/octopus/proxy_config.rb index 93a2e5bc..2be7aadd 100644 --- a/lib/octopus/proxy_config.rb +++ b/lib/octopus/proxy_config.rb @@ -138,7 +138,11 @@ def initialize_shards(config) self.shards_slave_groups = HashWithIndifferentAccess.new self.slave_groups = HashWithIndifferentAccess.new self.groups = {} - self.config = ActiveRecord::Base.connection_pool_without_octopus.spec.config + self.config = if Octopus.atleast_rails61? + ActiveRecord::Base.connection_pool_without_octopus.db_config.configuration_hash + else + ActiveRecord::Base.connection_pool_without_octopus.spec.config + end unless config.nil? self.entire_sharded = config['entire_sharded'] @@ -217,14 +221,19 @@ def reinitialize_shards private def connection_pool_for(config, adapter) - if Octopus.rails4? + if Octopus.atleast_rails61? + name = config["octopus_shard"] + db_config = ActiveRecord::DatabaseConfigurations::HashConfig.new(Octopus.rails_env, name, config) + pool_config = ActiveRecord::ConnectionAdapters::PoolConfig.new(ActiveRecord::Base, db_config) + ActiveRecord::ConnectionAdapters::ConnectionPool.new(pool_config) + elsif Octopus.rails4? spec = ActiveRecord::ConnectionAdapters::ConnectionSpecification.new(config.dup, adapter ) + ActiveRecord::ConnectionAdapters::ConnectionPool.new(spec) else name = adapter["octopus_shard"] spec = ActiveRecord::ConnectionAdapters::ConnectionSpecification.new(name, config.dup, adapter) + ActiveRecord::ConnectionAdapters::ConnectionPool.new(spec) end - - ActiveRecord::ConnectionAdapters::ConnectionPool.new(spec) end def resolve_string_connection(spec)