active_record_proxy_adapters 0.1.0.rc2 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a84998cef36e3e7ba5c4e69909a41db4641a22aaa2b589988fe38f74abefa600
4
- data.tar.gz: e0ab2ac9b05420d952c89f7259c6d3539eadf7b44fd791bb178dc28e91066b30
3
+ metadata.gz: 265cb32e99a265497548122846934c46405747109fa3bee34d1e2e66203b14a3
4
+ data.tar.gz: d9de3faf7274a0a94166637032c0a967e083edf55fc275b2456123d3f9a7ee79
5
5
  SHA512:
6
- metadata.gz: 39d6c4508378596812e6dbdf523e05ff662b279ace17f6ec0ec2db24171645374e9447fe5aff6e6a9f9f2bfb227fce4a0dddc6deebe016b2d2a1f62234f198f9
7
- data.tar.gz: 8b423c0d1464157eff63c0c161481acb2a2ba55e95f9337c4a27819c1acbfe41ccf83e7e59bdb98cea1e80419159b475060a166336251c59759d4298fe0c502f
6
+ metadata.gz: 871504b4290e8304effa5e30962a8db9fdab6663c73b4f9d9e99edf403af630755ddaaafa557619a86430812b7e54e19931274ec71dd4f86a7b4dc32b73fc669
7
+ data.tar.gz: f7605b374452517ae3346d896d043e092539abd0a86445eb1a04defbd7516628a70bcd5157fca10c730b7ee6fe047733d1e8e4d65a016c49651cbb12f7e8dcee
data/.rubocop.yml CHANGED
@@ -14,7 +14,3 @@ Style/StringLiteralsInInterpolation:
14
14
  RSpec/NestedGroups:
15
15
  Enabled: true
16
16
  Max: 5
17
-
18
- # TODO: Enable MFA once we open source the gem
19
- Gemspec/RequireMFA:
20
- Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.1.0] - 2024-11-19
2
+
3
+ - Add PostgreSQLProxyAdapter
4
+
1
5
  ## [0.1.0.rc2] - 2024-10-28
2
6
 
3
7
  - Add PostgreSQLProxyAdapter
data/README.md CHANGED
@@ -4,15 +4,13 @@ A set of ActiveRecord adapters that leverage Rails native multiple database setu
4
4
 
5
5
  ## Installation
6
6
 
7
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
8
-
9
7
  Install the gem and add to the application's Gemfile by executing:
10
8
 
11
- $ bundle add 'UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG'
9
+ $ bundle add 'active_record_proxy_adapters'
12
10
 
13
11
  If bundler is not being used to manage dependencies, install the gem by executing:
14
12
 
15
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
13
+ $ gem install active_record_proxy_adapters
16
14
 
17
15
  ## Usage
18
16
 
@@ -2,8 +2,9 @@
2
2
 
3
3
  require "active_record/tasks/postgresql_proxy_database_tasks"
4
4
  require "active_record/connection_adapters/postgresql_adapter"
5
- require "active_record_proxy_adapters/postgresql_proxy"
5
+ require "active_record_proxy_adapters/active_record_context"
6
6
  require "active_record_proxy_adapters/hijackable"
7
+ require "active_record_proxy_adapters/postgresql_proxy"
7
8
 
8
9
  module ActiveRecord
9
10
  module ConnectionAdapters
@@ -14,7 +15,11 @@ module ActiveRecord
14
15
 
15
16
  ADAPTER_NAME = "PostgreSQLProxy"
16
17
 
17
- delegate_to_proxy :execute, :exec_query, :exec_no_cache, :exec_cache
18
+ delegate_to_proxy :execute, :exec_query
19
+
20
+ unless ActiveRecordProxyAdapters::ActiveRecordContext.active_record_v8_0_or_greater?
21
+ delegate_to_proxy :exec_no_cache, :exec_cache
22
+ end
18
23
 
19
24
  def initialize(...)
20
25
  @proxy = ActiveRecordProxyAdapters::PostgreSQLProxy.new(self)
@@ -29,7 +34,7 @@ module ActiveRecord
29
34
  end
30
35
  end
31
36
 
32
- if ActiveRecordProxyAdapters::ActiveRecordContext.active_record_v7_2?
37
+ if ActiveRecordProxyAdapters::ActiveRecordContext.active_record_v7_2_or_greater?
33
38
  ActiveRecord::ConnectionAdapters.register(
34
39
  "postgresql_proxy",
35
40
  "ActiveRecord::ConnectionAdapters::PostgreSQLProxyAdapter",
@@ -4,7 +4,7 @@ module ActiveRecordProxyAdapters
4
4
  # Collection of helpers to handle common active record methods that are defined in different places in different
5
5
  # versions of rails.
6
6
  class ActiveRecordContext
7
- delegate :reading_role, :reading_role=, :writing_role, :writing_role=, to: :role_context
7
+ delegate :reading_role, :reading_role=, :writing_role, :writing_role=, to: :ActiveRecord
8
8
  delegate :legacy_connection_handling, :legacy_connection_handling=, to: :connection_handling_context
9
9
  delegate :version, to: :ActiveRecord, prefix: :active_record
10
10
 
@@ -22,45 +22,27 @@ module ActiveRecordProxyAdapters
22
22
  end
23
23
  end
24
24
 
25
- def reading_role
26
- role_context.reading_role
27
- end
28
-
29
- def writing_role
30
- role_context.writing_role
31
- end
32
-
33
25
  def connection_class_for(connection)
34
- klass = active_record_v6_1? ? connection.connection_klass : connection.connection_class
35
-
36
- klass || ActiveRecord::Base
26
+ connection.connection_class || ActiveRecord::Base
37
27
  end
38
28
 
39
29
  def connection_handling_context
40
30
  # This config option has been removed in Rails 7.1+
41
- return NullConnectionHandlingContext.new if active_record_v7_1? || active_record_v7_2?
42
-
43
- global_configuration_context
44
- end
45
-
46
- def role_context
47
- global_configuration_context
48
- end
31
+ return NullConnectionHandlingContext.new if active_record_v7_1_or_greater?
49
32
 
50
- def global_configuration_context
51
- active_record_v6_1? ? ActiveRecord::Base : ActiveRecord
33
+ ActiveRecord
52
34
  end
53
35
 
54
- def active_record_v6_1?
55
- active_record_version >= Gem::Version.new("6.1") && active_record_version < Gem::Version.new("7.0")
36
+ def active_record_v7_1_or_greater?
37
+ active_record_version >= Gem::Version.new("7.1")
56
38
  end
57
39
 
58
- def active_record_v7_1?
59
- active_record_version >= Gem::Version.new("7.1") && active_record_version < Gem::Version.new("7.2")
40
+ def active_record_v7_2_or_greater?
41
+ active_record_version >= Gem::Version.new("7.2")
60
42
  end
61
43
 
62
- def active_record_v7_2?
63
- active_record_version >= Gem::Version.new("7.2") && active_record_version < Gem::Version.new("8.0")
44
+ def active_record_v8_0_or_greater?
45
+ active_record_version >= Gem::Version.new("8.0")
64
46
  end
65
47
  end
66
48
  end
@@ -1,11 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_record_proxy_adapters/primary_replica_proxy"
4
+ require "active_record_proxy_adapters/active_record_context"
4
5
 
5
6
  module ActiveRecordProxyAdapters
6
7
  # Proxy to the original PostgreSQLAdapter, allowing the use of the ActiveRecordProxyAdapters::PrimaryReplicaProxy.
7
8
  class PostgreSQLProxy < PrimaryReplicaProxy
8
9
  # ActiveRecord::PostgreSQLAdapter methods that should be proxied.
9
- hijack_method :execute, :exec_query, :exec_no_cache, :exec_cache
10
+ hijack_method :execute, :exec_query
11
+
12
+ hijack_method :exec_no_cache, :exec_cache unless ActiveRecordContext.active_record_v8_0_or_greater?
10
13
  end
11
14
  end
@@ -29,7 +29,10 @@ module ActiveRecordProxyAdapters
29
29
 
30
30
  # Defines which methods should be hijacked from the original adapter and use the proxy
31
31
  # @param method_names [Array<Symbol>] the list of method names from the adapter
32
- def self.hijack_method(*method_names)
32
+ def self.hijack_method(*method_names) # rubocop:disable Metrics/MethodLength
33
+ @hijacked_methods ||= Set.new
34
+ @hijacked_methods += Set.new(method_names)
35
+
33
36
  method_names.each do |method_name|
34
37
  define_method(method_name) do |*args, **kwargs, &block|
35
38
  proxy_bypass_method = "#{method_name}#{UNPROXIED_METHOD_SUFFIX}"
@@ -44,6 +47,10 @@ module ActiveRecordProxyAdapters
44
47
  end
45
48
  end
46
49
 
50
+ def self.hijacked_methods
51
+ @hijacked_methods.to_a
52
+ end
53
+
47
54
  # @param primary_connection [ActiveRecord::ConnectionAdatpers::AbstractAdapter]
48
55
  def initialize(primary_connection)
49
56
  @primary_connection = primary_connection
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordProxyAdapters
4
- VERSION = "0.1.0.rc2"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_proxy_adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.rc2
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Cruz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-27 00:00:00.000000000 Z
11
+ date: 2024-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,40 +16,40 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 6.1.a
19
+ version: 7.0.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '8.0'
22
+ version: '8.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 6.1.a
29
+ version: 7.0.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '8.0'
32
+ version: '8.1'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: activesupport
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 6.1.a
39
+ version: 7.0.0
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: '8.0'
42
+ version: '8.1'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 6.1.a
49
+ version: 7.0.0
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
- version: '8.0'
52
+ version: '8.1'
53
53
  description: |-
54
54
  This gem allows automatic connection switching between a primary and one read replica database in ActiveRecord.
55
55
  It pattern matches the SQL statement being sent to decide whether it should go to the replica (SELECT) or the
@@ -91,6 +91,7 @@ metadata:
91
91
  homepage_uri: https://github.com/Nasdaq/active_record_proxy_adapters
92
92
  source_code_uri: https://github.com/Nasdaq/active_record_proxy_adapters
93
93
  changelog_uri: https://github.com/Nasdaq/active_record_proxy_adapters/blob/main/CHANGELOG.md
94
+ rubygems_mfa_required: 'true'
94
95
  post_install_message:
95
96
  rdoc_options: []
96
97
  require_paths: