Skip to content

Commit

Permalink
Get started with Rails 7.1 support
Browse files Browse the repository at this point in the history
  • Loading branch information
zendesk-yianna committed Apr 2, 2024
1 parent a99b759 commit d054a8f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
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
resolved_shard ? name : PRIMARY
end
end
Expand Down

0 comments on commit d054a8f

Please sign in to comment.