active_record_proxy_adapters 0.8.1 → 0.10.1

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.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -1
  3. data/lib/active_record/connection_adapters/mysql2_proxy_adapter.rb +0 -6
  4. data/lib/active_record/connection_adapters/postgresql_proxy_adapter.rb +0 -6
  5. data/lib/active_record/connection_adapters/trilogy_proxy_adapter.rb +0 -6
  6. data/lib/active_record_proxy_adapters/active_record_context.rb +2 -34
  7. data/lib/active_record_proxy_adapters/configuration.rb +15 -1
  8. data/lib/active_record_proxy_adapters/connection_handling/mysql2_proxy.rb +8 -0
  9. data/lib/active_record_proxy_adapters/connection_handling/postgresql_proxy.rb +8 -0
  10. data/lib/active_record_proxy_adapters/connection_handling/sqlite3_proxy.rb +8 -0
  11. data/lib/active_record_proxy_adapters/connection_handling/trilogy_proxy.rb +8 -0
  12. data/lib/active_record_proxy_adapters/connection_handling.rb +4 -4
  13. data/lib/active_record_proxy_adapters/core.rb +13 -0
  14. data/lib/active_record_proxy_adapters/log_subscriber.rb +1 -11
  15. data/lib/active_record_proxy_adapters/mixin/configuration.rb +0 -1
  16. data/lib/active_record_proxy_adapters/primary_replica_proxy.rb +3 -6
  17. data/lib/active_record_proxy_adapters/railtie.rb +5 -12
  18. data/lib/active_record_proxy_adapters/railties/mysql2.rb +13 -0
  19. data/lib/active_record_proxy_adapters/railties/postgresql.rb +21 -0
  20. data/lib/active_record_proxy_adapters/railties/sqlite3.rb +21 -0
  21. data/lib/active_record_proxy_adapters/railties/trilogy.rb +13 -0
  22. data/lib/active_record_proxy_adapters/version.rb +1 -1
  23. data/lib/active_record_proxy_adapters.rb +0 -19
  24. metadata +19 -29
  25. data/lib/active_record_proxy_adapters/connection_handling/mysql2.rb +0 -45
  26. data/lib/active_record_proxy_adapters/connection_handling/postgresql.rb +0 -46
  27. data/lib/active_record_proxy_adapters/connection_handling/sqlite3.rb +0 -68
  28. data/lib/active_record_proxy_adapters/connection_handling/trilogy.rb +0 -44
  29. data/lib/active_record_proxy_adapters/transactionable_proxy_a_r_70.rb +0 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a5c79bbbfc75972477b105dbee115b4107a12b3a326164c8ef3562c16910609a
4
- data.tar.gz: d7276cdc0c42fb138fdf662c867ff3e3e2abcb2a2b58904d8080b630f91e6ac6
3
+ metadata.gz: ef6a98229ff0dd2f30d7737792821deeda8b445e2eac66f1c025e82465aa6f34
4
+ data.tar.gz: f368b3f0d102a55646f3a95238eaa8fd4366dfaebd060906085a11fd52c285ec
5
5
  SHA512:
6
- metadata.gz: e0cb991cc6c4f4f49fcdb330e2d4254a13fd0e8b3a10f2ce9cf38f9dac36305c9c0ad148d2660839e354d2fd9b251ce0d92df5c05fd45414b0d1b298cd03df6c
7
- data.tar.gz: d98aa2d8ddf561875041c9807604e1b13fbda7600bee9b2528cb7a34beb700d0540f9750f69a7d4fa10a0f3074bce71d1ad2f51b28701d018784c68a81edc78d
6
+ metadata.gz: '084a6b96bf5c17af4eda2137527443a92acbab1eed930046cd2920fb827bcf0ec253eb3d5c038879830e66f4beb8daab51225d068759423413ab0dfd386ed606'
7
+ data.tar.gz: 5ba78c23e63f0d6281465402025dccbf17d09deae578c496704d33b6389dbc6e12d7f2bff849c40593349ca260e43efb44d2a9605935da1b8dd541bea05d5311
data/README.md CHANGED
@@ -25,6 +25,18 @@ Install the gem and add to the application's Gemfile by executing:
25
25
 
26
26
  $ bundle add 'active_record_proxy_adapters'
27
27
 
28
+ That will install and load the proxies for all Rails-supported adapters (i.e. `postgresql_proxy`, `mysql2_proxy`, `sqlite3_proxy` and `trilogy_proxy`).
29
+
30
+ If you wish to load only one specific adapter for a faster application boot, use:
31
+
32
+ $ bundle add 'active_record_proxy_adapters' --require 'active_record_proxy_adapters/railties/<postgresql|mysql2|sqlite3|trilogy>'
33
+
34
+ Or, in your Gemfile, use:
35
+
36
+ ```ruby
37
+ gem "active_record_proxy_adapters", require: 'active_record_proxy_adapters/railties/<postgresql|mysql2|sqlite3|trilogy>'
38
+ ```
39
+
28
40
  If bundler is not being used to manage dependencies, install the gem by executing:
29
41
 
30
42
  $ gem install active_record_proxy_adapters
@@ -558,7 +570,7 @@ To create a proxy adapter for an existing database `FoobarAdapter`, follow these
558
570
  return
559
571
  end
560
572
 
561
- # This is only required for Rails 7.0 or earlier.
573
+ # This is only required for Rails 7.1 or earlier.
562
574
  module ActiveRecordProxyAdapters
563
575
  module Foobar
564
576
  module ConnectionHandling
@@ -13,12 +13,6 @@ module ActiveRecord
13
13
  class Mysql2ProxyAdapter < Mysql2Adapter
14
14
  include ActiveRecordProxyAdapters::Hijackable
15
15
 
16
- if ActiveRecordProxyAdapters::ActiveRecordContext.active_record_v7_0?
17
- require "active_record_proxy_adapters/transactionable_proxy_a_r_70"
18
-
19
- include ActiveRecordProxyAdapters::TransactionableProxyAR70
20
- end
21
-
22
16
  ADAPTER_NAME = "Mysql2Proxy"
23
17
 
24
18
  delegate_to_proxy(*ActiveRecordProxyAdapters::ActiveRecordContext.hijackable_methods)
@@ -13,12 +13,6 @@ module ActiveRecord
13
13
  class PostgreSQLProxyAdapter < PostgreSQLAdapter
14
14
  include ActiveRecordProxyAdapters::Hijackable
15
15
 
16
- if ActiveRecordProxyAdapters::ActiveRecordContext.active_record_v7_0?
17
- require "active_record_proxy_adapters/transactionable_proxy_a_r_70"
18
-
19
- include ActiveRecordProxyAdapters::TransactionableProxyAR70
20
- end
21
-
22
16
  ADAPTER_NAME = "PostgreSQLProxy"
23
17
 
24
18
  delegate_to_proxy(*ActiveRecordProxyAdapters::ActiveRecordContext.hijackable_methods)
@@ -13,12 +13,6 @@ module ActiveRecord
13
13
  class TrilogyProxyAdapter < TrilogyAdapter
14
14
  include ActiveRecordProxyAdapters::Hijackable
15
15
 
16
- if ActiveRecordProxyAdapters::ActiveRecordContext.active_record_v7_0?
17
- require "active_record_proxy_adapters/transactionable_proxy_a_r_70"
18
-
19
- include ActiveRecordProxyAdapters::TransactionableProxyAR70
20
- end
21
-
22
16
  ADAPTER_NAME = "TrilogyProxy"
23
17
 
24
18
  delegate_to_proxy(*ActiveRecordProxyAdapters::ActiveRecordContext.hijackable_methods)
@@ -5,56 +5,24 @@ module ActiveRecordProxyAdapters
5
5
  # versions of rails.
6
6
  class ActiveRecordContext
7
7
  delegate :reading_role, :reading_role=, :writing_role, :writing_role=, to: :ActiveRecord
8
- delegate :legacy_connection_handling, :legacy_connection_handling=, to: :connection_handling_context
9
8
  delegate :version, to: :ActiveRecord, prefix: :active_record
10
9
 
11
10
  class << self
12
11
  delegate_missing_to :new
13
12
  end
14
13
 
15
- # rubocop:disable Naming/PredicateMethod
16
- NullConnectionHandlingContext = Class.new do
17
- def legacy_connection_handling
18
- false
19
- end
20
-
21
- def legacy_connection_handling=(_value)
22
- nil
23
- end
24
- end
25
- # rubocop:enable Naming/PredicateMethod
26
-
27
14
  def connection_class_for(connection)
28
15
  return connection.connection_descriptor.name.constantize if active_record_v8_0_2_or_greater?
29
16
 
30
17
  connection.connection_class || ActiveRecord::Base
31
18
  end
32
19
 
33
- def connection_handling_context
34
- # This config option has been removed in Rails 7.1+
35
- return NullConnectionHandlingContext.new if active_record_v7_1_or_greater?
36
-
37
- ActiveRecord
38
- end
39
-
40
20
  def hijackable_methods
41
- hijackable = %i[execute exec_query]
42
-
43
- hijackable << :internal_exec_query if active_record_v7_1_or_greater?
44
-
45
- hijackable
21
+ %i[exec_delete exec_insert exec_query exec_update execute select]
46
22
  end
47
23
 
48
24
  def active_record_v7?
49
- active_record_version >= Gem::Version.new("7.0") && active_record_version < Gem::Version.new("8.0")
50
- end
51
-
52
- def active_record_v7_0?
53
- active_record_version >= Gem::Version.new("7.0") && active_record_version < Gem::Version.new("7.1")
54
- end
55
-
56
- def active_record_v7_1_or_greater?
57
- active_record_version >= Gem::Version.new("7.1")
25
+ active_record_version >= Gem::Version.new("7.2") && active_record_version < Gem::Version.new("8.0")
58
26
  end
59
27
 
60
28
  def active_record_v7_2_or_greater?
@@ -8,7 +8,21 @@ require "active_record_proxy_adapters/synchronizable_configuration"
8
8
  require "active_support/core_ext/integer/time"
9
9
  require "logger"
10
10
 
11
- module ActiveRecordProxyAdapters
11
+ module ActiveRecordProxyAdapters # rubocop:disable Style/Documentation
12
+ module_function
13
+
14
+ def configure
15
+ yield(config)
16
+ end
17
+
18
+ def bust_query_cache
19
+ config.cache.bust
20
+ end
21
+
22
+ def config
23
+ @config ||= Configuration.new
24
+ end
25
+
12
26
  # Provides a global configuration object to configure how the proxy should behave.
13
27
  class Configuration
14
28
  include SynchronizableConfiguration
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require "active_record/connection_adapters/mysql2_proxy_adapter"
5
+ rescue LoadError
6
+ # mysql2 not available
7
+ return
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require "active_record/connection_adapters/postgresql_proxy_adapter"
5
+ rescue LoadError
6
+ # Postgres not available
7
+ return
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require "active_record/connection_adapters/sqlite3_proxy_adapter"
5
+ rescue LoadError
6
+ # sqlite3 not available
7
+ return
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require "active_record/connection_adapters/trilogy_proxy_adapter"
5
+ rescue LoadError
6
+ # trilogy not available
7
+ return
8
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_record_proxy_adapters/connection_handling/postgresql"
4
- require "active_record_proxy_adapters/connection_handling/mysql2"
5
- require "active_record_proxy_adapters/connection_handling/trilogy"
6
- require "active_record_proxy_adapters/connection_handling/sqlite3"
3
+ require "active_record_proxy_adapters/connection_handling/postgresql_proxy"
4
+ require "active_record_proxy_adapters/connection_handling/mysql2_proxy"
5
+ require "active_record_proxy_adapters/connection_handling/trilogy_proxy"
6
+ require "active_record_proxy_adapters/connection_handling/sqlite3_proxy"
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_record"
4
+ require "active_record_proxy_adapters/version"
5
+ require "active_record_proxy_adapters/active_record_context"
6
+ require "active_record_proxy_adapters/configuration"
7
+ require "active_record_proxy_adapters/context"
8
+ require "active_record_proxy_adapters/contextualizer"
9
+ require "active_record_proxy_adapters/database_tasks"
10
+ require "active_record_proxy_adapters/errors"
11
+ require "active_record_proxy_adapters/hijackable"
12
+ require "active_record_proxy_adapters/mixin/configuration"
13
+ require "active_record_proxy_adapters/primary_replica_proxy"
@@ -22,22 +22,12 @@ module ActiveRecordProxyAdapters
22
22
 
23
23
  def database_instance_prefix_for(event)
24
24
  connection = event.payload[:connection]
25
- db_config = connection.pool.try(:db_config) || NullConfig.new # AR 7.0.x does not support "NullConfig"
25
+ db_config = connection.pool.try(:db_config)
26
26
  connection_name = db_config.name
27
27
 
28
28
  prefix = log_subscriber_prefix(connection_name)
29
29
 
30
30
  "[#{prefix.call(event)}]"
31
31
  end
32
-
33
- class NullConfig # rubocop:disable Style/Documentation
34
- def method_missing(...)
35
- nil
36
- end
37
-
38
- def respond_to_missing?(*)
39
- true
40
- end
41
- end
42
32
  end
43
33
  end
@@ -3,7 +3,6 @@
3
3
  require "active_support/core_ext/integer/time"
4
4
  require "active_record_proxy_adapters/synchronizable_configuration"
5
5
  require "active_record_proxy_adapters/cache_configuration"
6
- require "active_record_proxy_adapters/context"
7
6
 
8
7
  module ActiveRecordProxyAdapters
9
8
  module Mixin
@@ -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
@@ -160,8 +159,7 @@ module ActiveRecordProxyAdapters
160
159
  end
161
160
 
162
161
  def pending_migration_connection?
163
- active_record_context.active_record_v7_1_or_greater? &&
164
- connection_class.name == "ActiveRecord::PendingMigrationConnection"
162
+ connection_class.name == "ActiveRecord::PendingMigrationConnection"
165
163
  end
166
164
 
167
165
  def connection_for(role, sql_string)
@@ -224,9 +222,8 @@ module ActiveRecordProxyAdapters
224
222
 
225
223
  def match_sql?(sql_string)
226
224
  proc do |matcher|
227
- # TODO: switch to regexp timeout once Ruby 3.1 support is dropped.
228
- Timeout.timeout(proxy_checkout_timeout.to_f) { matcher.match?(sql_string) }
229
- rescue Timeout::Error
225
+ Regexp.new(matcher.source, Regexp::IGNORECASE, timeout: proxy_checkout_timeout.to_f).match?(sql_string)
226
+ rescue Regexp::TimeoutError
230
227
  regexp_timeout_strategy.call(sql_string, matcher)
231
228
 
232
229
  false
@@ -1,25 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_support"
4
+ require "active_record_proxy_adapters/core"
5
+ require "active_record_proxy_adapters/railties/postgresql"
6
+ require "active_record_proxy_adapters/railties/mysql2"
7
+ require "active_record_proxy_adapters/railties/trilogy"
8
+ require "active_record_proxy_adapters/railties/sqlite3"
4
9
 
5
10
  module ActiveRecordProxyAdapters
6
11
  # Hooks into rails boot process to extend ActiveRecord with the proxy adapter.
7
12
  class Railtie < Rails::Railtie
8
- require "active_record_proxy_adapters/connection_handling"
9
13
  require "active_record_proxy_adapters/middleware"
10
14
  require "active_record_proxy_adapters/rake"
11
15
 
12
- config.to_prepare do
13
- Rails.autoloaders.each do |autoloader|
14
- autoloader.inflector.inflect(
15
- "postgresql_proxy_adapter" => "PostgreSQLProxyAdapter"
16
- )
17
- autoloader.inflector.inflect(
18
- "sqlite3_proxy_adapter" => "SQLite3ProxyAdapter"
19
- )
20
- end
21
- end
22
-
23
16
  initializer "active_record_proxy_adapters.configure_rails_initialization" do |app|
24
17
  app.middleware.use ActiveRecordProxyAdapters::Middleware
25
18
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support"
4
+ require "active_record_proxy_adapters/core"
5
+
6
+ module ActiveRecordProxyAdapters
7
+ module Railties
8
+ # Hooks into rails boot process to load the Mysql2 Proxy adapter.
9
+ class Mysql2Proxy < Rails::Railtie
10
+ require "active_record_proxy_adapters/connection_handling/mysql2_proxy"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support"
4
+ require "active_record_proxy_adapters/core"
5
+
6
+ module ActiveRecordProxyAdapters
7
+ module Railties
8
+ # Hooks into rails boot process to load the PostgreSQL Proxy adapter.
9
+ class PostgreSQLProxy < Rails::Railtie
10
+ require "active_record_proxy_adapters/connection_handling/postgresql_proxy"
11
+
12
+ config.to_prepare do
13
+ Rails.autoloaders.each do |autoloader|
14
+ autoloader.inflector.inflect(
15
+ "postgresql_proxy_adapter" => "PostgreSQLProxyAdapter"
16
+ )
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support"
4
+ require "active_record_proxy_adapters/core"
5
+
6
+ module ActiveRecordProxyAdapters
7
+ module Railties
8
+ # Hooks into rails boot process to load the SQLite3 Proxy adapter.
9
+ class SQLite3Proxy < Rails::Railtie
10
+ require "active_record_proxy_adapters/connection_handling/sqlite3_proxy"
11
+
12
+ config.to_prepare do
13
+ Rails.autoloaders.each do |autoloader|
14
+ autoloader.inflector.inflect(
15
+ "sqlite3_proxy_adapter" => "SQLite3ProxyAdapter"
16
+ )
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support"
4
+ require "active_record_proxy_adapters/core"
5
+
6
+ module ActiveRecordProxyAdapters
7
+ module Railties
8
+ # Hooks into rails boot process to load the Trilogy Proxy adapter.
9
+ class TrilogyProxy < Rails::Railtie
10
+ require "active_record_proxy_adapters/connection_handling/trilogy_proxy"
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordProxyAdapters
4
- VERSION = "0.8.1"
4
+ VERSION = "0.10.1"
5
5
  end
@@ -1,26 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_record"
4
- require "active_record_proxy_adapters/version"
5
- require "active_record_proxy_adapters/configuration"
6
-
7
3
  # The gem namespace.
8
4
  module ActiveRecordProxyAdapters
9
- class Error < StandardError; end
10
-
11
- module_function
12
-
13
- def configure
14
- yield(config)
15
- end
16
-
17
- def bust_query_cache
18
- config.cache.bust
19
- end
20
-
21
- def config
22
- @config ||= Configuration.new
23
- end
24
5
  end
25
6
 
26
7
  require_relative "active_record_proxy_adapters/railtie" if defined?(Rails::Railtie)
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.8.1
4
+ version: 0.10.1
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.0.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.0.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.0.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.0.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
@@ -132,12 +118,13 @@ files:
132
118
  - lib/active_record_proxy_adapters/cache_configuration.rb
133
119
  - lib/active_record_proxy_adapters/configuration.rb
134
120
  - lib/active_record_proxy_adapters/connection_handling.rb
135
- - lib/active_record_proxy_adapters/connection_handling/mysql2.rb
136
- - lib/active_record_proxy_adapters/connection_handling/postgresql.rb
137
- - lib/active_record_proxy_adapters/connection_handling/sqlite3.rb
138
- - lib/active_record_proxy_adapters/connection_handling/trilogy.rb
121
+ - lib/active_record_proxy_adapters/connection_handling/mysql2_proxy.rb
122
+ - lib/active_record_proxy_adapters/connection_handling/postgresql_proxy.rb
123
+ - lib/active_record_proxy_adapters/connection_handling/sqlite3_proxy.rb
124
+ - lib/active_record_proxy_adapters/connection_handling/trilogy_proxy.rb
139
125
  - lib/active_record_proxy_adapters/context.rb
140
126
  - lib/active_record_proxy_adapters/contextualizer.rb
127
+ - lib/active_record_proxy_adapters/core.rb
141
128
  - lib/active_record_proxy_adapters/database_configuration.rb
142
129
  - lib/active_record_proxy_adapters/database_tasks.rb
143
130
  - lib/active_record_proxy_adapters/errors.rb
@@ -149,11 +136,14 @@ files:
149
136
  - lib/active_record_proxy_adapters/postgresql_proxy.rb
150
137
  - lib/active_record_proxy_adapters/primary_replica_proxy.rb
151
138
  - lib/active_record_proxy_adapters/railtie.rb
139
+ - lib/active_record_proxy_adapters/railties/mysql2.rb
140
+ - lib/active_record_proxy_adapters/railties/postgresql.rb
141
+ - lib/active_record_proxy_adapters/railties/sqlite3.rb
142
+ - lib/active_record_proxy_adapters/railties/trilogy.rb
152
143
  - lib/active_record_proxy_adapters/rake.rb
153
144
  - lib/active_record_proxy_adapters/sqlite3_proxy.rb
154
145
  - lib/active_record_proxy_adapters/synchronizable_configuration.rb
155
146
  - lib/active_record_proxy_adapters/tasks/arpa.rake
156
- - lib/active_record_proxy_adapters/transactionable_proxy_a_r_70.rb
157
147
  - lib/active_record_proxy_adapters/trilogy_proxy.rb
158
148
  - lib/active_record_proxy_adapters/version.rb
159
149
  homepage: https://github.com/Nasdaq/active_record_proxy_adapters
@@ -172,7 +162,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
172
162
  requirements:
173
163
  - - ">="
174
164
  - !ruby/object:Gem::Version
175
- version: 3.1.0
165
+ version: 3.2.0
176
166
  required_rubygems_version: !ruby/object:Gem::Requirement
177
167
  requirements:
178
168
  - - ">="
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- begin
4
- require "active_record/connection_adapters/mysql2_proxy_adapter"
5
- rescue LoadError
6
- # mysql2 not available
7
- return
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
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- begin
4
- require "active_record/connection_adapters/postgresql_proxy_adapter"
5
- rescue LoadError
6
- # Postgres not available
7
- return
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
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- begin
4
- require "active_record/connection_adapters/sqlite3_proxy_adapter"
5
- rescue LoadError
6
- # sqlite3 not available
7
- return
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
- connection_factory_mapping
21
- .fetch("#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}")
22
- .call(config)
23
- end
24
-
25
- def connection_factory_mapping
26
- {
27
- "7.0" => ->(config) { sqlite3_proxy_connection_ar_v70(config) },
28
- "7.1" => ->(config) { sqlite3_proxy_connection_ar_v71(config) }
29
- }
30
- end
31
-
32
- def sqlite3_proxy_connection_ar_v70(config) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength
33
- config = config.symbolize_keys
34
-
35
- # Require database.
36
- raise ArgumentError, "No database file specified. Missing argument: database" unless config[:database]
37
-
38
- # Allow database path relative to Rails.root, but only if the database
39
- # path is not the special path that tells sqlite to build a database only
40
- # in memory.
41
- if ":memory:" != config[:database] && !config[:database].to_s.start_with?("file:") # rubocop:disable Style/YodaCondition
42
- config[:database] = File.expand_path(config[:database], Rails.root) if defined?(Rails.root)
43
- dirname = File.dirname(config[:database])
44
- Dir.mkdir(dirname) unless File.directory?(dirname)
45
- end
46
-
47
- db = ::SQLite3::Database.new(
48
- config[:database].to_s,
49
- config.merge(results_as_hash: true)
50
- )
51
-
52
- sqlite3_proxy_adapter_class.new(db, logger, nil, config)
53
- rescue Errno::ENOENT => e
54
- raise ActiveRecord::NoDatabaseError if e.message.include?("No such file or directory")
55
-
56
- raise
57
- end
58
-
59
- def sqlite3_proxy_connection_ar_v71(config)
60
- sqlite3_proxy_adapter_class.new(config)
61
- end
62
- end
63
- end
64
- end
65
-
66
- ActiveSupport.on_load(:active_record) do
67
- ActiveRecord::Base.extend(ActiveRecordProxyAdapters::SQLite3::ConnectionHandling)
68
- end
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- begin
4
- require "active_record/connection_adapters/trilogy_proxy_adapter"
5
- rescue LoadError
6
- # trilogy not available
7
- return
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,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActiveRecordProxyAdapters
4
- module TransactionableProxyAR70 # rubocop:disable Style/Documentation
5
- extend ActiveSupport::Concern
6
-
7
- included do
8
- def begin_db_transaction # :nodoc:
9
- bypass_proxy_or_else("BEGIN", "TRANSACTION") { super }
10
- end
11
-
12
- def commit_db_transaction # :nodoc:
13
- bypass_proxy_or_else("COMMIT", "TRANSACTION") { super }
14
- end
15
-
16
- def exec_rollback_db_transaction # :nodoc:
17
- bypass_proxy_or_else("ROLLBACK", "TRANSACTION") { super }
18
- end
19
-
20
- private
21
-
22
- def bypass_proxy_or_else(*args)
23
- method_name = proxy_method_name_for(:execute)
24
-
25
- return public_send(method_name, *args) if respond_to?(method_name)
26
-
27
- yield
28
- end
29
- end
30
- end
31
- end