active_record_host_pool 4.1.0 → 4.2.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 +4 -4
- data/Changelog.md +12 -0
- data/Readme.md +16 -1
- data/lib/active_record_host_pool/clear_query_cache_patch.rb +0 -11
- data/lib/active_record_host_pool/connection_adapter_mixin.rb +16 -38
- data/lib/active_record_host_pool/pool_proxy.rb +23 -31
- data/lib/active_record_host_pool/version.rb +1 -1
- data/lib/active_record_host_pool.rb +7 -14
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3944318de7c004909c8bc75a447e01e9ec1c5a44d0eb99f0449cc53880ec0d74
|
4
|
+
data.tar.gz: 1b0ec3c13a90206c9a2f02a6c0c51b92a9053ba3858a979268eea071c52c26ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9742fce5b0960f281e1e119f2e326b1b90a921f534da452f2fd67c289d18cbbdec6324dafab53e6053745f5a5bd69f01b927dcde2005fe6daaab184943758de
|
7
|
+
data.tar.gz: 69766e4f3747c105c4b98b86609faa3cb9eee8105951faa82627da8117c4eb36f66c4b5edf34e59f6fb44b25c0a47ca9242065de1eef65dcc15636a7188312bd
|
data/Changelog.md
CHANGED
@@ -6,6 +6,18 @@ and as of v1.0.0 this project adheres to [Semantic Versioning](https://semver.or
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [4.2.0]
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
- ActiveRecordHostPool can now work with `mysql2` and `trilogy` if both gems are loaded.
|
13
|
+
|
14
|
+
### Added
|
15
|
+
- Testing with Rails 8.0.
|
16
|
+
|
17
|
+
### Removed
|
18
|
+
- Support for Rails 6.1 & 7.0.
|
19
|
+
- Support for Ruby 3.1.
|
20
|
+
|
9
21
|
## [4.1.0]
|
10
22
|
|
11
23
|
### Changed
|
data/Readme.md
CHANGED
@@ -50,7 +50,7 @@ Postgres, from an informal reading of the docs, will never support the concept o
|
|
50
50
|
|
51
51
|
$ gem install active_record_host_pool
|
52
52
|
|
53
|
-
and make sure to require '
|
53
|
+
and make sure to require 'active_record_host_pool' in some way.
|
54
54
|
|
55
55
|
## Testing
|
56
56
|
You need a local user called 'john-doe'.
|
@@ -68,6 +68,21 @@ With mysql running locally, run
|
|
68
68
|
|
69
69
|
BUNDLE_GEMFILE=gemfiles/rails6.1.gemfile ruby test/test_arhp.rb --seed 19911 --verbose
|
70
70
|
|
71
|
+
### Releasing a new version
|
72
|
+
A new version is published to RubyGems.org every time a change to `version.rb` is pushed to the `main` branch.
|
73
|
+
In short, follow these steps:
|
74
|
+
1. Update `version.rb`,
|
75
|
+
2. update version in all `Gemfile.lock` files,
|
76
|
+
3. merge this change into `main`, and
|
77
|
+
4. look at [the action](https://github.com/zendesk/active_record_host_pool/actions/workflows/publish.yml) for output.
|
78
|
+
|
79
|
+
To create a pre-release from a non-main branch:
|
80
|
+
1. change the version in `version.rb` to something like `1.2.0.pre.1` or `2.0.0.beta.2`,
|
81
|
+
2. push this change to your branch,
|
82
|
+
3. go to [Actions → “Publish to RubyGems.org” on GitHub](https://github.com/zendesk/active_record_host_pool/actions/workflows/publish.yml),
|
83
|
+
4. click the “Run workflow” button,
|
84
|
+
5. pick your branch from a dropdown.
|
85
|
+
|
71
86
|
## Copyright
|
72
87
|
|
73
88
|
Copyright (c) 2011 Zendesk. See MIT-LICENSE for details.
|
@@ -25,21 +25,10 @@ module ActiveRecordHostPool
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
28
|
-
|
29
|
-
# For Rails 6.1 & 7.0.
|
30
|
-
module ClearOnHandlerPatch
|
31
|
-
def clear_on_handler(handler)
|
32
|
-
handler.all_connection_pools.each do |pool|
|
33
|
-
pool._unproxied_connection.clear_query_cache if pool.active_connection?
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
28
|
end
|
38
29
|
|
39
30
|
case "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"
|
40
31
|
when "7.1"
|
41
32
|
# Fix https://github.com/rails/rails/commit/401e2f24161ed6047ae33c322aaf6584b7728ab9
|
42
33
|
ActiveRecord::Base.singleton_class.prepend(ActiveRecordHostPool::ClearQueryCachePatch)
|
43
|
-
when "6.1", "7.0"
|
44
|
-
ActiveRecord::Base.singleton_class.prepend(ActiveRecordHostPool::ClearOnHandlerPatch)
|
45
34
|
end
|
@@ -1,18 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
when :mysql2
|
3
|
+
begin
|
5
4
|
require "active_record/connection_adapters/mysql2_adapter"
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
raise "Unsupported version of Rails (v#{ActiveRecord::VERSION::STRING})"
|
15
|
-
end
|
5
|
+
rescue LoadError
|
6
|
+
:noop
|
7
|
+
end
|
8
|
+
|
9
|
+
begin
|
10
|
+
require "active_record/connection_adapters/trilogy_adapter"
|
11
|
+
rescue LoadError
|
12
|
+
:noop
|
16
13
|
end
|
17
14
|
|
18
15
|
module ActiveRecordHostPool
|
@@ -28,24 +25,10 @@ module ActiveRecordHostPool
|
|
28
25
|
@config[:database] = _host_pool_desired_database
|
29
26
|
end
|
30
27
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
yield real_connection
|
36
|
-
end
|
37
|
-
end
|
38
|
-
elsif ActiveRecordHostPool.loaded_db_adapter == :trilogy
|
39
|
-
def with_trilogy_connection(...)
|
40
|
-
super do |real_connection|
|
41
|
-
_switch_connection(real_connection) if _host_pool_desired_database && !_no_switch
|
42
|
-
yield real_connection
|
43
|
-
end
|
44
|
-
end
|
45
|
-
else
|
46
|
-
def execute(...)
|
47
|
-
_switch_connection(raw_connection) if _host_pool_desired_database && !_no_switch
|
48
|
-
super
|
28
|
+
def with_raw_connection(...)
|
29
|
+
super do |real_connection|
|
30
|
+
_switch_connection(real_connection) if _host_pool_desired_database && !_no_switch
|
31
|
+
yield real_connection
|
49
32
|
end
|
50
33
|
end
|
51
34
|
|
@@ -94,7 +77,7 @@ module ActiveRecordHostPool
|
|
94
77
|
|
95
78
|
# rubocop:disable Lint/DuplicateMethods
|
96
79
|
case "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"
|
97
|
-
when "
|
80
|
+
when "7.1"
|
98
81
|
def _real_connection_object_id
|
99
82
|
@connection.object_id
|
100
83
|
end
|
@@ -122,11 +105,6 @@ module ActiveRecordHostPool
|
|
122
105
|
end
|
123
106
|
end
|
124
107
|
|
125
|
-
|
126
|
-
|
127
|
-
ActiveRecord::ConnectionAdapters::Mysql2Adapter.prepend(ActiveRecordHostPool::DatabaseSwitch)
|
128
|
-
when :trilogy
|
129
|
-
ActiveRecord::ConnectionAdapters::TrilogyAdapter.prepend(ActiveRecordHostPool::DatabaseSwitch)
|
130
|
-
end
|
131
|
-
|
108
|
+
ActiveRecord::ConnectionAdapters::Mysql2Adapter.prepend(ActiveRecordHostPool::DatabaseSwitch) if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
|
109
|
+
ActiveRecord::ConnectionAdapters::TrilogyAdapter.prepend(ActiveRecordHostPool::DatabaseSwitch) if defined?(ActiveRecord::ConnectionAdapters::TrilogyAdapter)
|
132
110
|
ActiveRecord::ConnectionAdapters::PoolConfig.prepend(ActiveRecordHostPool::PoolConfigPatch)
|
@@ -15,13 +15,23 @@ require "active_record_host_pool/connection_adapter_mixin"
|
|
15
15
|
module ActiveRecordHostPool
|
16
16
|
# Sits between ConnectionHandler and a bunch of different ConnectionPools (one per host).
|
17
17
|
class PoolProxy < Delegator
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
rescuable_db_error = []
|
19
|
+
begin
|
20
|
+
require "mysql2"
|
21
|
+
rescuable_db_error << Mysql2::Error
|
22
|
+
rescue LoadError
|
23
|
+
:noop
|
23
24
|
end
|
24
25
|
|
26
|
+
begin
|
27
|
+
require "trilogy"
|
28
|
+
rescuable_db_error << Trilogy::ProtocolError
|
29
|
+
rescue LoadError
|
30
|
+
:noop
|
31
|
+
end
|
32
|
+
|
33
|
+
RESCUABLE_DB_ERROR = rescuable_db_error.freeze
|
34
|
+
|
25
35
|
def initialize(pool_config)
|
26
36
|
super
|
27
37
|
@pool_config = pool_config
|
@@ -43,11 +53,11 @@ module ActiveRecordHostPool
|
|
43
53
|
|
44
54
|
# rubocop:disable Lint/DuplicateMethods
|
45
55
|
case "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"
|
46
|
-
when "
|
56
|
+
when "7.1"
|
47
57
|
def connection(*args)
|
48
58
|
real_connection = _unproxied_connection(*args)
|
49
59
|
_connection_proxy_for(real_connection, @config[:database])
|
50
|
-
rescue RESCUABLE_DB_ERROR, ActiveRecord::NoDatabaseError, ActiveRecord::StatementInvalid
|
60
|
+
rescue *RESCUABLE_DB_ERROR, ActiveRecord::NoDatabaseError, ActiveRecord::StatementInvalid
|
51
61
|
_connection_pools.delete(_pool_key)
|
52
62
|
Kernel.raise
|
53
63
|
end
|
@@ -59,7 +69,7 @@ module ActiveRecordHostPool
|
|
59
69
|
def lease_connection(*args)
|
60
70
|
real_connection = _unproxied_connection(*args)
|
61
71
|
_connection_proxy_for(real_connection, @config[:database])
|
62
|
-
rescue RESCUABLE_DB_ERROR, ActiveRecord::NoDatabaseError, ActiveRecord::StatementInvalid
|
72
|
+
rescue *RESCUABLE_DB_ERROR, ActiveRecord::NoDatabaseError, ActiveRecord::StatementInvalid
|
63
73
|
_connection_pools.delete(_pool_key)
|
64
74
|
Kernel.raise
|
65
75
|
end
|
@@ -84,7 +94,7 @@ module ActiveRecordHostPool
|
|
84
94
|
end
|
85
95
|
|
86
96
|
case "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"
|
87
|
-
when "
|
97
|
+
when "7.1"
|
88
98
|
def with_connection
|
89
99
|
cx = checkout
|
90
100
|
yield cx
|
@@ -197,30 +207,12 @@ module ActiveRecordHostPool
|
|
197
207
|
pool
|
198
208
|
end
|
199
209
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
when "6.1", "7.0"
|
204
|
-
def _connection_proxy_for(connection, database)
|
205
|
-
@connection_proxy_cache ||= {}
|
206
|
-
key = [connection, database]
|
207
|
-
|
208
|
-
@connection_proxy_cache[key] ||= begin
|
209
|
-
cx = ActiveRecordHostPool::ConnectionProxy.new(connection, database)
|
210
|
-
cx.execute("SELECT 1")
|
210
|
+
def _connection_proxy_for(connection, database)
|
211
|
+
@connection_proxy_cache ||= {}
|
212
|
+
key = [connection, database]
|
211
213
|
|
212
|
-
|
213
|
-
end
|
214
|
-
end
|
215
|
-
else
|
216
|
-
def _connection_proxy_for(connection, database)
|
217
|
-
@connection_proxy_cache ||= {}
|
218
|
-
key = [connection, database]
|
219
|
-
|
220
|
-
@connection_proxy_cache[key] ||= ActiveRecordHostPool::ConnectionProxy.new(connection, database)
|
221
|
-
end
|
214
|
+
@connection_proxy_cache[key] ||= ActiveRecordHostPool::ConnectionProxy.new(connection, database)
|
222
215
|
end
|
223
|
-
# standard:enable Lint/DuplicateMethods
|
224
216
|
|
225
217
|
def _clear_connection_proxy_cache
|
226
218
|
@connection_proxy_cache = {}
|
@@ -4,23 +4,16 @@ require "active_record"
|
|
4
4
|
require "active_record/base"
|
5
5
|
require "active_record/connection_adapters/abstract_adapter"
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
begin
|
8
|
+
require "mysql2"
|
9
|
+
rescue LoadError
|
10
|
+
:noop
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
require "mysql2"
|
15
|
-
ActiveRecordHostPool.loaded_db_adapter = :mysql2
|
16
|
-
elsif Gem.loaded_specs.include?("trilogy")
|
13
|
+
begin
|
17
14
|
require "trilogy"
|
18
|
-
|
19
|
-
|
20
|
-
require "trilogy_adapter/version"
|
21
|
-
raise "ActiveRecordHostPool is only compatible with activerecord-trilogy-adapter v3.1+" if Gem::Version.new("3.1") > TrilogyAdapter::VERSION
|
22
|
-
end
|
23
|
-
ActiveRecordHostPool.loaded_db_adapter = :trilogy
|
15
|
+
rescue LoadError
|
16
|
+
:noop
|
24
17
|
end
|
25
18
|
|
26
19
|
require "active_record_host_pool/clear_query_cache_patch"
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_host_pool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Quorning
|
8
8
|
- Gabe Martin-Dempesy
|
9
9
|
- Pierre Schambacher
|
10
10
|
- Ben Osheroff
|
11
|
-
autorequire:
|
11
|
+
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2025-04-18 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activerecord
|
@@ -19,14 +19,14 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: 7.1.0
|
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:
|
29
|
+
version: 7.1.0
|
30
30
|
description: ''
|
31
31
|
email:
|
32
32
|
- bquorning@zendesk.com
|
@@ -51,7 +51,7 @@ homepage: https://github.com/zendesk/active_record_host_pool
|
|
51
51
|
licenses:
|
52
52
|
- MIT
|
53
53
|
metadata: {}
|
54
|
-
post_install_message:
|
54
|
+
post_install_message:
|
55
55
|
rdoc_options: []
|
56
56
|
require_paths:
|
57
57
|
- lib
|
@@ -59,15 +59,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
59
59
|
requirements:
|
60
60
|
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: 3.
|
62
|
+
version: 3.2.0
|
63
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
65
|
- - ">="
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: '0'
|
68
68
|
requirements: []
|
69
|
-
rubygems_version: 3.
|
70
|
-
signing_key:
|
69
|
+
rubygems_version: 3.4.19
|
70
|
+
signing_key:
|
71
71
|
specification_version: 4
|
72
72
|
summary: Allow ActiveRecord to share a connection to multiple databases on the same
|
73
73
|
host
|