active_record_proxy_adapters 0.9.3 → 0.10.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: b272f6fe240bd15128438342d9fad9d81d94c9c6b5a41b188639eae55801b58d
4
- data.tar.gz: 37a8b6a65f7ace36976a6bb2c0c868f2a85401b0ee3a3cfbde32f7a17eafbf4a
3
+ metadata.gz: bca625e0a728907c505db941a4398b5aa144dcdd5f6866ac9a3969f0b783c4d0
4
+ data.tar.gz: 3ab824330a83e8309b31763b24fe7c74ba0efff2a1eff28505d2a8216442f557
5
5
  SHA512:
6
- metadata.gz: 157760e5eee20e9c92a4a269e26ad4b8afa41d2f5557a6fcfcdd04bc3323709a5c7d8cde8a4e0165ff1cb7f5c71c0d758a5c804ef67c67bed0dbcbf8424bb403
7
- data.tar.gz: 909e6ddc7b82eb18b7a98f5481a24ff127126b49a69664f39b33d285157821eb769b908a41bab68a61334dc634aac5e8d78b8a7198f7fe7268e9be79b5dfcfac
6
+ metadata.gz: 1bc0567abfff9e1877abe107074a7e3f35f574ecefc2584f188809a0940c37a9192c88f3ae71f0e682d7115de75cd8b82ef827874e75195dc635572a8a8c7173
7
+ data.tar.gz: 6ee734e3da7c41d458403e10589d3edd8126862ddcfa2d63034d75c884ec98e383c58e0877166c25155c44ef3a2c13e307378df850b47b0da77d103ff31d57c2
@@ -15,7 +15,7 @@ module ActiveRecord
15
15
 
16
16
  ADAPTER_NAME = "TrilogyProxy"
17
17
 
18
- delegate_to_proxy(*ActiveRecordProxyAdapters::ActiveRecordContext.hijackable_methods)
18
+ delegate_to_proxy(*ActiveRecordProxyAdapters::ActiveRecordContext.hijackable_methods, :exec_insert)
19
19
 
20
20
  def initialize(...)
21
21
  @proxy = ActiveRecordProxyAdapters::TrilogyProxy.new(self)
@@ -18,11 +18,11 @@ module ActiveRecordProxyAdapters
18
18
  end
19
19
 
20
20
  def hijackable_methods
21
- %i[exec_delete exec_insert exec_query exec_update execute select]
21
+ %i[execute exec_query internal_exec_query]
22
22
  end
23
23
 
24
24
  def active_record_v7?
25
- active_record_version >= Gem::Version.new("7.1") && active_record_version < Gem::Version.new("8.0")
25
+ active_record_version >= Gem::Version.new("7.2") && active_record_version < Gem::Version.new("8.0")
26
26
  end
27
27
 
28
28
  def active_record_v7_2_or_greater?
@@ -6,40 +6,3 @@ rescue LoadError
6
6
  # mysql2 not available
7
7
  return
8
8
  end
9
-
10
- module ActiveRecordProxyAdapters
11
- module Mysql2
12
- # Module to extend ActiveRecord::Base with the connection handling methods.
13
- # Required to make adapter work in ActiveRecord versions <= 7.2.x
14
- module ConnectionHandling
15
- def mysql2_proxy_adapter_class
16
- ::ActiveRecord::ConnectionAdapters::Mysql2ProxyAdapter
17
- end
18
-
19
- # This method is a copy and paste from Rails' mysql2_connection,
20
- # replacing Mysql2Adapter by Mysql2ProxyAdapter
21
- # This is required by ActiveRecord versions <= 7.2.x to establish a connection using the adapter.
22
- def mysql2_proxy_connection(config) # rubocop:disable Metrics/MethodLength
23
- config = config.symbolize_keys
24
- config[:flags] ||= 0
25
-
26
- if config[:flags].is_a? Array
27
- config[:flags].push "FOUND_ROWS"
28
- else
29
- config[:flags] |= ::Mysql2::Client::FOUND_ROWS
30
- end
31
-
32
- mysql2_proxy_adapter_class.new(
33
- mysql2_proxy_adapter_class.new_client(config),
34
- logger,
35
- nil,
36
- config
37
- )
38
- end
39
- end
40
- end
41
- end
42
-
43
- ActiveSupport.on_load(:active_record) do
44
- ActiveRecord::Base.extend(ActiveRecordProxyAdapters::Mysql2::ConnectionHandling)
45
- end
@@ -6,41 +6,3 @@ rescue LoadError
6
6
  # Postgres not available
7
7
  return
8
8
  end
9
-
10
- module ActiveRecordProxyAdapters
11
- # Module to extend ActiveRecord::Base with the connection handling methods.
12
- # Required to make adapter work in ActiveRecord versions <= 7.2.x
13
- module PostgreSQL
14
- module ConnectionHandling # rubocop:disable Style/Documentation
15
- def postgresql_proxy_adapter_class
16
- ::ActiveRecord::ConnectionAdapters::PostgreSQLProxyAdapter
17
- end
18
-
19
- # This method is a copy and paste from Rails' postgresql_connection,
20
- # replacing PostgreSQLAdapter by PostgreSQLProxyAdapter
21
- # This is required by ActiveRecord versions <= 7.2.x to establish a connection using the adapter.
22
- def postgresql_proxy_connection(config) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
23
- conn_params = config.symbolize_keys.compact
24
-
25
- # Map ActiveRecords param names to PGs.
26
- conn_params[:user] = conn_params.delete(:username) if conn_params[:username]
27
- conn_params[:dbname] = conn_params.delete(:database) if conn_params[:database]
28
-
29
- # Forward only valid config params to PG::Connection.connect.
30
- valid_conn_param_keys = PG::Connection.conndefaults_hash.keys + [:requiressl]
31
- conn_params.slice!(*valid_conn_param_keys)
32
-
33
- postgresql_proxy_adapter_class.new(
34
- postgresql_proxy_adapter_class.new_client(conn_params),
35
- logger,
36
- conn_params,
37
- config
38
- )
39
- end
40
- end
41
- end
42
- end
43
-
44
- ActiveSupport.on_load(:active_record) do
45
- ActiveRecord::Base.extend(ActiveRecordProxyAdapters::PostgreSQL::ConnectionHandling)
46
- end
@@ -6,23 +6,3 @@ rescue LoadError
6
6
  # sqlite3 not available
7
7
  return
8
8
  end
9
-
10
- module ActiveRecordProxyAdapters
11
- module SQLite3
12
- # Module to extend ActiveRecord::Base with the connection handling methods.
13
- # Required to make adapter work in ActiveRecord versions <= 7.2.x
14
- module ConnectionHandling
15
- def sqlite3_proxy_adapter_class
16
- ActiveRecord::ConnectionAdapters::SQLite3ProxyAdapter
17
- end
18
-
19
- def sqlite3_proxy_connection(config)
20
- sqlite3_proxy_adapter_class.new(config)
21
- end
22
- end
23
- end
24
- end
25
-
26
- ActiveSupport.on_load(:active_record) do
27
- ActiveRecord::Base.extend(ActiveRecordProxyAdapters::SQLite3::ConnectionHandling)
28
- end
@@ -6,39 +6,3 @@ rescue LoadError
6
6
  # trilogy not available
7
7
  return
8
8
  end
9
-
10
- module ActiveRecordProxyAdapters
11
- module Trilogy
12
- # Module to extend ActiveRecord::Base with the connection handling methods.
13
- # Required to make adapter work in ActiveRecord versions <= 7.2.x
14
- module ConnectionHandling
15
- def trilogy_proxy_adapter_class
16
- ActiveRecord::ConnectionAdapters::TrilogyProxyAdapter
17
- end
18
-
19
- def trilogy_proxy_connection(config) # rubocop:disable Metrics/MethodLength
20
- configuration = config.dup
21
-
22
- # Set FOUND_ROWS capability on the connection so UPDATE queries returns number of rows
23
- # matched rather than number of rows updated.
24
- configuration[:found_rows] = true
25
-
26
- options = [
27
- configuration[:host],
28
- configuration[:port],
29
- configuration[:database],
30
- configuration[:username],
31
- configuration[:password],
32
- configuration[:socket],
33
- 0
34
- ]
35
-
36
- trilogy_proxy_adapter_class.new nil, logger, options, configuration
37
- end
38
- end
39
- end
40
- end
41
-
42
- ActiveSupport.on_load(:active_record) do
43
- ActiveRecord::Base.extend(ActiveRecordProxyAdapters::Trilogy::ConnectionHandling)
44
- end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "rack"
4
- require "rack/events"
5
4
  require "json"
6
5
  require "active_record_proxy_adapters/context"
7
6
  require "active_record_proxy_adapters/contextualizer"
@@ -44,16 +43,6 @@ module ActiveRecordProxyAdapters
44
43
  Rack::Utils.set_cookie_header!(headers, COOKIE_NAME, cookie)
45
44
  end.freeze
46
45
 
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
-
57
46
  def initialize(app, cookie_options = {})
58
47
  @app = app
59
48
  @cookie_options = cookie_options
@@ -7,7 +7,6 @@ require "active_record_proxy_adapters/hijackable"
7
7
  require "active_record_proxy_adapters/mixin/configuration"
8
8
  require "active_support/core_ext/module/delegation"
9
9
  require "active_support/core_ext/object/blank"
10
- require "timeout"
11
10
 
12
11
  module ActiveRecordProxyAdapters
13
12
  # This is the base class for all proxies. It defines the methods that should be proxied
@@ -223,9 +222,8 @@ module ActiveRecordProxyAdapters
223
222
 
224
223
  def match_sql?(sql_string)
225
224
  proc do |matcher|
226
- # TODO: switch to regexp timeout once Ruby 3.1 support is dropped.
227
- Timeout.timeout(proxy_checkout_timeout.to_f) { matcher.match?(sql_string) }
228
- rescue Timeout::Error
225
+ Regexp.new(matcher.source, Regexp::IGNORECASE, timeout: proxy_checkout_timeout.to_f).match?(sql_string)
226
+ rescue Regexp::TimeoutError
229
227
  regexp_timeout_strategy.call(sql_string, matcher)
230
228
 
231
229
  false
@@ -2,17 +2,21 @@
2
2
 
3
3
  require "active_support"
4
4
  require "active_record_proxy_adapters/core"
5
- require "active_record_proxy_adapters/railties/mysql2"
6
5
  require "active_record_proxy_adapters/railties/postgresql"
7
- require "active_record_proxy_adapters/railties/rack_middleware"
8
- require "active_record_proxy_adapters/railties/sqlite3"
6
+ require "active_record_proxy_adapters/railties/mysql2"
9
7
  require "active_record_proxy_adapters/railties/trilogy"
8
+ require "active_record_proxy_adapters/railties/sqlite3"
10
9
 
11
10
  module ActiveRecordProxyAdapters
12
11
  # Hooks into rails boot process to extend ActiveRecord with the proxy adapter.
13
12
  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
+
16
20
  rake_tasks do
17
21
  ActiveRecordProxyAdapters::Rake.load_tasks
18
22
  ActiveRecordProxyAdapters::Rake.enhance_db_tasks
@@ -5,5 +5,6 @@ require "active_record_proxy_adapters/mysql2_proxy"
5
5
  module ActiveRecordProxyAdapters
6
6
  # Proxy to the Mysql2Proxy, allowing the use of the ActiveRecordProxyAdapters::PrimaryReplicaProxy.
7
7
  class TrilogyProxy < Mysql2Proxy
8
+ hijack_method :exec_insert
8
9
  end
9
10
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordProxyAdapters
4
- VERSION = "0.9.3"
4
+ VERSION = "0.10.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.9.3
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Cruz
@@ -15,40 +15,40 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 7.1.0
18
+ version: 7.2.0
19
19
  - - "<"
20
20
  - !ruby/object:Gem::Version
21
- version: '8.1'
21
+ version: '8.2'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: 7.1.0
28
+ version: 7.2.0
29
29
  - - "<"
30
30
  - !ruby/object:Gem::Version
31
- version: '8.1'
31
+ version: '8.2'
32
32
  - !ruby/object:Gem::Dependency
33
33
  name: activesupport
34
34
  requirement: !ruby/object:Gem::Requirement
35
35
  requirements:
36
36
  - - ">="
37
37
  - !ruby/object:Gem::Version
38
- version: 7.1.0
38
+ version: 7.2.0
39
39
  - - "<"
40
40
  - !ruby/object:Gem::Version
41
- version: '8.1'
41
+ version: '8.2'
42
42
  type: :runtime
43
43
  prerelease: false
44
44
  version_requirements: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ">="
47
47
  - !ruby/object:Gem::Version
48
- version: 7.1.0
48
+ version: 7.2.0
49
49
  - - "<"
50
50
  - !ruby/object:Gem::Version
51
- version: '8.1'
51
+ version: '8.2'
52
52
  - !ruby/object:Gem::Dependency
53
53
  name: digest
54
54
  requirement: !ruby/object:Gem::Requirement
@@ -91,20 +91,6 @@ dependencies:
91
91
  - - ">="
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
- - !ruby/object:Gem::Dependency
95
- name: timeout
96
- requirement: !ruby/object:Gem::Requirement
97
- requirements:
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- version: '0'
101
- type: :runtime
102
- prerelease: false
103
- version_requirements: !ruby/object:Gem::Requirement
104
- requirements:
105
- - - ">="
106
- - !ruby/object:Gem::Version
107
- version: '0'
108
94
  description: |-
109
95
  This gem allows automatic connection switching between a primary and one read replica database in ActiveRecord.
110
96
  It pattern matches the SQL statement being sent to decide whether it should go to the replica (SELECT) or the
@@ -152,7 +138,6 @@ files:
152
138
  - lib/active_record_proxy_adapters/railtie.rb
153
139
  - lib/active_record_proxy_adapters/railties/mysql2.rb
154
140
  - lib/active_record_proxy_adapters/railties/postgresql.rb
155
- - lib/active_record_proxy_adapters/railties/rack_middleware.rb
156
141
  - lib/active_record_proxy_adapters/railties/sqlite3.rb
157
142
  - lib/active_record_proxy_adapters/railties/trilogy.rb
158
143
  - lib/active_record_proxy_adapters/rake.rb
@@ -1,14 +0,0 @@
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