Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Experimental] Minimum support for Rails 6.1 #583

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/octopus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/octopus/collection_association.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 13 additions & 4 deletions lib/octopus/proxy_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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)
Expand Down