ros-apartment 3.4.1 → 3.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c1a77f61c7ac94816e7f0a0d906435cf2f9f06d7efc979a7308ac41a99c4247
4
- data.tar.gz: '08bdfedeaba0107f0931a2a1f438b2dffebcdd4df89381b5be97f7bd9de5b7d3'
3
+ metadata.gz: 2ff5e16756f5fc42560082bd07204b8853c85a4b4d15ce38664585b2e6631ccc
4
+ data.tar.gz: 168b28a0141dca9bdbdc80ea6ecf3247677b7dc138ca6d3feed213d24c11b454
5
5
  SHA512:
6
- metadata.gz: c09415eddebce74732c14bf8f71ec3a4d8dab0e53f6df5d15439068964b2de79ac57c36253878456866e2021d6c8faf1a6f1a3ae12961b33d33a4118536128e3
7
- data.tar.gz: db8413aa220b089dd0ab874051a5bf990e2f02b9a10da80e7e2356b8fbfd4a908346811ce6f8da0d9fc028c111fe9829ab495807e481a8b268353332d2e0c2bd
6
+ metadata.gz: c8899404718944dae59cc218ac48c558f6005cce6bb6f61357bca1f3a69e8e9a0bbef7950d60effcc1a02efde0ecc65062fc258565a5375a7991cc3ad2d0a293
7
+ data.tar.gz: 4b4aa74a1194609b254a3e08c00d493243842396f045560d6909ae3c67751dbb183d56545046bb61508f61e039ee2159875fe8fb2766d15f20cea28068a8504a
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Style/ClassAndModuleChildren
3
+ # rubocop:disable Style/ClassAndModuleChildren, Style/OneClassPerFile
4
4
 
5
5
  # NOTE: This patch is meant to remove any schema_prefix appart from the ones for
6
6
  # excluded models. The schema_prefix would be resolved by apartment's setting
@@ -55,4 +55,4 @@ require 'active_record/connection_adapters/postgresql_adapter'
55
55
  class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
56
56
  include Apartment::PostgreSqlAdapterPatch
57
57
  end
58
- # rubocop:enable Style/ClassAndModuleChildren
58
+ # rubocop:enable Style/ClassAndModuleChildren, Style/OneClassPerFile
@@ -41,7 +41,7 @@ module Apartment
41
41
  raise(ActiveRecord::StatementInvalid, "Could not find schema #{tenant}") unless schema_exists?(tenant)
42
42
 
43
43
  @current = tenant.is_a?(Array) ? tenant.map(&:to_s) : tenant.to_s
44
- Apartment.connection.schema_search_path = full_search_path
44
+ set_schema_search_path(full_search_path)
45
45
  rescue ActiveRecord::StatementInvalid, ActiveRecord::JDBCError
46
46
  raise(TenantNotFound, "One of the following schema(s) is invalid: #{full_search_path}")
47
47
  end
@@ -41,12 +41,12 @@ module Apartment
41
41
  #
42
42
  def reset
43
43
  @current = default_tenant
44
- Apartment.connection.schema_search_path = full_search_path
44
+ set_schema_search_path(full_search_path)
45
45
  end
46
46
 
47
47
  def init
48
48
  super
49
- Apartment.connection.schema_search_path = full_search_path
49
+ set_schema_search_path(full_search_path)
50
50
  end
51
51
 
52
52
  def current
@@ -76,13 +76,35 @@ module Apartment
76
76
  raise(ActiveRecord::StatementInvalid, "Could not find schema #{tenant}") unless schema_exists?(tenant)
77
77
 
78
78
  @current = tenant.is_a?(Array) ? tenant.map(&:to_s) : tenant.to_s
79
- Apartment.connection.schema_search_path = full_search_path
79
+ set_schema_search_path(full_search_path)
80
80
  rescue *rescuable_exceptions => e
81
81
  raise_schema_connect_to_new(tenant, e)
82
82
  end
83
83
 
84
84
  private
85
85
 
86
+ # Force a fresh +SET search_path+ even when ActiveRecord's
87
+ # +@schema_search_path+ cache still matches +value+. Rails 8.1 added a
88
+ # memoization early-return to PostgreSQLAdapter#schema_search_path= (see
89
+ # rails/rails#54698), which makes the assignment a no-op when the ivar
90
+ # is unchanged. After a transactional ROLLBACK or a connection reconnect
91
+ # the ivar can hold a stale value while the actual session search_path
92
+ # has reverted, so we must invalidate the ivar before reassigning.
93
+ # This is a cache-invalidating wrapper, not a plain writer.
94
+ #
95
+ # Maintenance note: this couples us to Rails' private
96
+ # +@schema_search_path+ ivar. Watch rails/rails#54698 for an upstream
97
+ # fix or a public invalidation API -- once one ships, this workaround
98
+ # should be dropped in favor of the public path. If a future Rails
99
+ # release renames or removes the ivar, this helper degrades silently
100
+ # back to the memoization no-op; the regression specs under
101
+ # +describe '#switch!'+ and +describe '#reset'+ in
102
+ # +spec/examples/schema_adapter_examples.rb+ are the canary.
103
+ def set_schema_search_path(value) # rubocop:disable Naming/AccessorMethodName
104
+ Apartment.connection.instance_variable_set(:@schema_search_path, nil)
105
+ Apartment.connection.schema_search_path = value
106
+ end
107
+
86
108
  def tenant_exists?(tenant)
87
109
  return true unless Apartment.tenant_presence_check
88
110
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Apartment
4
- VERSION = '3.4.1'
4
+ VERSION = '3.4.2'
5
5
  end
data/lib/apartment.rb CHANGED
@@ -164,17 +164,22 @@ module Apartment
164
164
  end
165
165
 
166
166
  # Exceptions
167
- ApartmentError = Class.new(StandardError)
167
+ class ApartmentError < StandardError
168
+ end
168
169
 
169
170
  # Raised when apartment cannot find the adapter specified in <tt>config/database.yml</tt>
170
- AdapterNotFound = Class.new(ApartmentError)
171
+ class AdapterNotFound < ApartmentError
172
+ end
171
173
 
172
174
  # Raised when apartment cannot find the file to be loaded
173
- FileNotFound = Class.new(ApartmentError)
175
+ class FileNotFound < ApartmentError
176
+ end
174
177
 
175
178
  # Tenant specified is unknown
176
- TenantNotFound = Class.new(ApartmentError)
179
+ class TenantNotFound < ApartmentError
180
+ end
177
181
 
178
182
  # The Tenant attempting to be created already exists
179
- TenantExists = Class.new(ApartmentError)
183
+ class TenantExists < ApartmentError
184
+ end
180
185
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ros-apartment
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.1
4
+ version: 3.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Brunner