Remove monkey patch for connected_to in Rails 7

ros-apartment 3.0.0+ includes official support for connection handling in Rails 7,
so we no longer need to override `ActiveRecord::ConnectionHandling#connected_to`.

References: PR #194 and #243 in ros-apartment
This commit is contained in:
taitus
2025-04-11 15:39:33 +02:00
parent 4d256b8a4e
commit b07e429356
2 changed files with 1 additions and 18 deletions

View File

@@ -48,7 +48,7 @@ gem "recipient_interceptor", "~> 0.3.3"
gem "redcarpet", "~> 3.6.0" gem "redcarpet", "~> 3.6.0"
gem "responders", "~> 3.1.1" gem "responders", "~> 3.1.1"
gem "rinku", "~> 2.0.6", require: "rails_rinku" gem "rinku", "~> 2.0.6", require: "rails_rinku"
gem "ros-apartment", "~> 3.2.0", require: "apartment" # Remove ConnectionHandling monkey patch when upgrading gem "ros-apartment", "~> 3.2.0", require: "apartment"
gem "sassc-embedded", "~> 1.77.5" gem "sassc-embedded", "~> 1.77.5"
gem "sassc-rails", "~> 2.1.2" gem "sassc-rails", "~> 2.1.2"
gem "savon", "~> 2.15.1" gem "savon", "~> 2.15.1"

View File

@@ -1,20 +1,3 @@
module ActiveRecord # TODO: Remove after upgrading ros-apartment
# Code based on the current (as of March 2024) development version of the apartment gem
module ConnectionHandling
def connected_to_with_rails7_tenant(role: nil, prevent_writes: false, &blk)
current_tenant = Apartment::Tenant.current
# The connected_to_without_tenant method is defined by Apartment
connected_to_without_tenant(role: role, prevent_writes: prevent_writes) do
Apartment::Tenant.switch!(current_tenant)
yield(blk)
end
end
alias connected_to connected_to_with_rails7_tenant
end
end
# You can have Apartment route to the appropriate Tenant by adding some Rack middleware. # You can have Apartment route to the appropriate Tenant by adding some Rack middleware.
# Apartment can support many different "Elevators" that can take care of this routing to your data. # Apartment can support many different "Elevators" that can take care of this routing to your data.
# Require whichever Elevator you're using below or none if you have a custom one. # Require whichever Elevator you're using below or none if you have a custom one.