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

Get started with Rails 7.1 support #333

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions active_record_shards.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Gem::Specification.new "active_record_shards", "5.5.0" do |s|

s.required_ruby_version = ">= 2.6"

s.add_runtime_dependency("activerecord", ">= 5.1", "< 7.1")
s.add_runtime_dependency("activesupport", ">= 5.1", "< 7.1")
s.add_runtime_dependency("activerecord", ">= 5.1", "<= 7.1")
s.add_runtime_dependency("activesupport", ">= 5.1", "<= 7.1")

s.add_development_dependency("bump")
s.add_development_dependency("minitest", ">= 5.10.0")
Expand Down
3 changes: 3 additions & 0 deletions gemfiles/rails7.1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
eval_gemfile 'common.rb'

gem 'activerecord', '~> 7.1.0'
2 changes: 1 addition & 1 deletion lib/active_record_shards.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def self.reset_app_env!

# https://github.com/rails/rails/blob/v5.2.6/activerecord/lib/active_record/associations/preloader/association.rb#L96
ActiveRecord::Associations::Preloader::Association.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsPreloaderAssociationLoadRecordsPatch)
when '6.0', '6.1', '7.0'
when '6.0', '6.1', '7.0', '7.1'
# https://github.com/rails/rails/blob/v6.0.4/activerecord/lib/active_record/type_caster/connection.rb#L28
ActiveRecord::TypeCaster::Connection.prepend(ActiveRecordShards::DefaultReplicaPatches::TypeCasterConnectionConnectionPatch)

Expand Down
2 changes: 1 addition & 1 deletion lib/active_record_shards/connection_switcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def method_missing(method, *args, &block) # rubocop:disable Style/MethodMissingS
require 'active_record_shards/connection_switcher-6-0'
when '6.1'
require 'active_record_shards/connection_switcher-6-1'
when '7.0'
when '7.0', '7.1'
require 'active_record_shards/connection_switcher-7-0'
else
raise "ActiveRecordShards is not compatible with #{ActiveRecord::VERSION::STRING}"
Expand Down
7 changes: 6 additions & 1 deletion lib/active_record_shards/shard_selection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def resolve_connection_name(sharded:, configurations:)
name << "_shard_#{resolved_shard}" if resolved_shard
replica_config = begin
case "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"
when '7.0'
when '7.0', '7.1'
binding.pry
configurations.configs_for(env_name: "#{name}_replica", include_hidden: true).any?
when '6.1'
configurations.configs_for(env_name: "#{name}_replica", include_replicas: true).any?
Expand All @@ -48,6 +49,10 @@ def resolve_connection_name(sharded:, configurations:)
else
# ActiveRecord always names its default connection pool 'primary'
# while everything else is named by the configuration name

# NOTE: for some reason this might need to return the environment.
# my 7.1 specs fail because see `connection_switcher-7-0.rb:8`
# configurations.configs_for(env_name: "primiary", include_hidden: true).any? == false
Comment on lines +52 to +55
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bquorning how is this sounding to you?

resolved_shard ? name : PRIMARY
end
end
Expand Down
Loading