active_record_proxy_adapters 0.10.1 → 0.11.0

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: ef6a98229ff0dd2f30d7737792821deeda8b445e2eac66f1c025e82465aa6f34
4
- data.tar.gz: f368b3f0d102a55646f3a95238eaa8fd4366dfaebd060906085a11fd52c285ec
3
+ metadata.gz: e9709c38149a112c5203c15ed59fe97903484dcc7842c82e070c57d29fea21ed
4
+ data.tar.gz: f9054fc5ce575e3d0877a4aa3b3ba9cd59da532c4b30d85536e4f63318119aee
5
5
  SHA512:
6
- metadata.gz: '084a6b96bf5c17af4eda2137527443a92acbab1eed930046cd2920fb827bcf0ec253eb3d5c038879830e66f4beb8daab51225d068759423413ab0dfd386ed606'
7
- data.tar.gz: 5ba78c23e63f0d6281465402025dccbf17d09deae578c496704d33b6389dbc6e12d7f2bff849c40593349ca260e43efb44d2a9605935da1b8dd541bea05d5311
6
+ metadata.gz: 7fe2bf87693040205f3e1aa62cc48b783d830b618d65423a4a8c3bae1dc029aae526d00227f5ca7ed4542dba04832641a86b2344ab6036956d3b2d9d1fc90b6b
7
+ data.tar.gz: 26c32105d9ed2c6f6d49016224284077207f780d0d3e56e62a59e81441808b1c00109f52c0baf867b09dba1a33a7aab2e12e4bc54b59789ddf288f0802e615cd
@@ -17,9 +17,24 @@ module ActiveRecordProxyAdapters
17
17
  connection.connection_class || ActiveRecord::Base
18
18
  end
19
19
 
20
+ # rubocop:disable Style/TrailingCommaInArrayLiteral
20
21
  def hijackable_methods
21
- %i[exec_delete exec_insert exec_query exec_update execute select]
22
+ [
23
+ # Create
24
+ :insert,
25
+ :exec_insert_all, # this one is an exception to the rule. there's no higher-level equivalent method to be called
26
+ # Retrieve
27
+ :select,
28
+ # Update
29
+ :update,
30
+ # Delete
31
+ :delete,
32
+ # Generic
33
+ :exec_query,
34
+ :execute,
35
+ ]
22
36
  end
37
+ # rubocop:enable Style/TrailingCommaInArrayLiteral
23
38
 
24
39
  def active_record_v7?
25
40
  active_record_version >= Gem::Version.new("7.2") && active_record_version < Gem::Version.new("8.0")
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "rack"
4
+ require "rack/events"
4
5
  require "json"
5
6
  require "active_record_proxy_adapters/context"
6
7
  require "active_record_proxy_adapters/contextualizer"
@@ -43,6 +44,16 @@ module ActiveRecordProxyAdapters
43
44
  Rack::Utils.set_cookie_header!(headers, COOKIE_NAME, cookie)
44
45
  end.freeze
45
46
 
47
+ class EventHandler # rubocop:disable Style/Documentation
48
+ include Rack::Events::Abstract
49
+ include Mixin::Configuration
50
+ include Contextualizer
51
+
52
+ def on_finish(_request, _response)
53
+ self.current_context = context_store.new({})
54
+ end
55
+ end
56
+
46
57
  def initialize(app, cookie_options = {})
47
58
  @app = app
48
59
  @cookie_options = cookie_options
@@ -102,7 +102,8 @@ module ActiveRecordProxyAdapters
102
102
  end
103
103
 
104
104
  def coerce_query_to_string(sql_or_arel)
105
- sql_or_arel.respond_to?(:to_sql) ? sql_or_arel.to_sql : sql_or_arel.to_s
105
+ # TODO: implement custom Proxy arel parser
106
+ sql_or_arel.respond_to?(:to_sql) ? sql_or_arel.to_sql(connection_class) : sql_or_arel.to_s
106
107
  end
107
108
 
108
109
  def appropriate_connection(sql_string, &block)
@@ -173,7 +174,14 @@ module ActiveRecordProxyAdapters
173
174
 
174
175
  result
175
176
  ensure
176
- replica_connection?(connection) && replica_pool.checkin(connection)
177
+ # Check the connection back into its own pool, not whatever pool currently
178
+ # answers to the :reading role. In Rails system tests,
179
+ # ActiveRecord::TestFixtures#setup_shared_connection_pool reassigns the
180
+ # :reading role's pool_config on every transactional-fixture test's
181
+ # before_setup, so re-resolving `replica_pool` here can return a pool
182
+ # different from the one the connection was checked out of — which would
183
+ # check a replica adapter into the primary pool and poison it.
184
+ connection.pool.checkin(connection) if replica_connection?(connection)
177
185
  end
178
186
 
179
187
  def connected_to(role:, &block)
@@ -2,21 +2,17 @@
2
2
 
3
3
  require "active_support"
4
4
  require "active_record_proxy_adapters/core"
5
- require "active_record_proxy_adapters/railties/postgresql"
6
5
  require "active_record_proxy_adapters/railties/mysql2"
7
- require "active_record_proxy_adapters/railties/trilogy"
6
+ require "active_record_proxy_adapters/railties/postgresql"
7
+ require "active_record_proxy_adapters/railties/rack_middleware"
8
8
  require "active_record_proxy_adapters/railties/sqlite3"
9
+ require "active_record_proxy_adapters/railties/trilogy"
9
10
 
10
11
  module ActiveRecordProxyAdapters
11
12
  # Hooks into rails boot process to extend ActiveRecord with the proxy adapter.
12
13
  class Railtie < Rails::Railtie
13
- require "active_record_proxy_adapters/middleware"
14
14
  require "active_record_proxy_adapters/rake"
15
15
 
16
- initializer "active_record_proxy_adapters.configure_rails_initialization" do |app|
17
- app.middleware.use ActiveRecordProxyAdapters::Middleware
18
- end
19
-
20
16
  rake_tasks do
21
17
  ActiveRecordProxyAdapters::Rake.load_tasks
22
18
  ActiveRecordProxyAdapters::Rake.enhance_db_tasks
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support"
4
+ require "active_record_proxy_adapters/middleware"
5
+
6
+ module ActiveRecordProxyAdapters
7
+ # Hooks into rails boot process to add the rack middleware for stickiness cookies.
8
+ class RackMiddleware < Rails::Railtie
9
+ initializer "active_record_proxy_adapters.add_middleware_to_rack_stack" do |app|
10
+ app.middleware.use ActiveRecordProxyAdapters::Middleware
11
+ app.middleware.use Rack::Events, [ActiveRecordProxyAdapters::Middleware::EventHandler.new]
12
+ end
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordProxyAdapters
4
- VERSION = "0.10.1"
4
+ VERSION = "0.11.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_proxy_adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Cruz
@@ -138,6 +138,7 @@ files:
138
138
  - lib/active_record_proxy_adapters/railtie.rb
139
139
  - lib/active_record_proxy_adapters/railties/mysql2.rb
140
140
  - lib/active_record_proxy_adapters/railties/postgresql.rb
141
+ - lib/active_record_proxy_adapters/railties/rack_middleware.rb
141
142
  - lib/active_record_proxy_adapters/railties/sqlite3.rb
142
143
  - lib/active_record_proxy_adapters/railties/trilogy.rb
143
144
  - lib/active_record_proxy_adapters/rake.rb