Sha256: 0dbc10ae43a7230387b0b4843b6c163dc3ec797bb6a33c2d886415795861c2cd
Contents?: true
Size: 750 Bytes
Versions: 8
Compression:
Stored size: 750 Bytes
Contents
# frozen_string_literal: true module ActiveRecord # This is monkeypatching activerecord to ensure that whenever a new connection is established it # switches to the same tenant as before the connection switching. This problem is more evident when # using read replica in Rails 6 module ConnectionHandling def connected_to_with_tenant(database: nil, role: nil, prevent_writes: false, &blk) current_tenant = Apartment::Tenant.current connected_to_without_tenant(database: database, role: role, prevent_writes: prevent_writes) do Apartment::Tenant.switch!(current_tenant) yield(blk) end end alias connected_to_without_tenant connected_to alias connected_to connected_to_with_tenant end end
Version data entries
8 entries across 8 versions & 1 rubygems