active_record_host_pool 1.2.4 → 2.0.0.pre.2
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 +112 -0
- data/Readme.md +3 -3
- data/lib/active_record_host_pool/clear_query_cache_patch.rb +13 -14
- data/lib/active_record_host_pool/connection_adapter_mixin.rb +50 -44
- data/lib/active_record_host_pool/connection_proxy.rb +3 -1
- data/lib/active_record_host_pool/pool_proxy.rb +182 -5
- data/lib/active_record_host_pool/version.rb +1 -1
- data/lib/active_record_host_pool.rb +21 -9
- metadata +11 -160
- data/lib/active_record_host_pool/pool_proxy_6_1.rb +0 -154
- data/lib/active_record_host_pool/pool_proxy_legacy.rb +0 -156
- data/test/database.yml +0 -108
- data/test/helper.rb +0 -198
- data/test/schema.rb +0 -23
- data/test/test_arhp.rb +0 -186
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_host_pool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.pre.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Quorning
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2023-
|
14
|
+
date: 2023-11-21 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activerecord
|
@@ -19,160 +19,20 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: 6.1.0
|
23
23
|
- - "<"
|
24
24
|
- !ruby/object:Gem::Version
|
25
|
-
version: '7.
|
25
|
+
version: '7.2'
|
26
26
|
type: :runtime
|
27
27
|
prerelease: false
|
28
28
|
version_requirements: !ruby/object:Gem::Requirement
|
29
29
|
requirements:
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: 6.1.0
|
33
33
|
- - "<"
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: '7.
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: mysql2
|
38
|
-
requirement: !ruby/object:Gem::Requirement
|
39
|
-
requirements:
|
40
|
-
- - ">="
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: '0'
|
43
|
-
type: :runtime
|
44
|
-
prerelease: false
|
45
|
-
version_requirements: !ruby/object:Gem::Requirement
|
46
|
-
requirements:
|
47
|
-
- - ">="
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: '0'
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
name: bump
|
52
|
-
requirement: !ruby/object:Gem::Requirement
|
53
|
-
requirements:
|
54
|
-
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: '0'
|
57
|
-
type: :development
|
58
|
-
prerelease: false
|
59
|
-
version_requirements: !ruby/object:Gem::Requirement
|
60
|
-
requirements:
|
61
|
-
- - ">="
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
version: '0'
|
64
|
-
- !ruby/object:Gem::Dependency
|
65
|
-
name: minitest
|
66
|
-
requirement: !ruby/object:Gem::Requirement
|
67
|
-
requirements:
|
68
|
-
- - ">="
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
version: 5.10.0
|
71
|
-
type: :development
|
72
|
-
prerelease: false
|
73
|
-
version_requirements: !ruby/object:Gem::Requirement
|
74
|
-
requirements:
|
75
|
-
- - ">="
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: 5.10.0
|
78
|
-
- !ruby/object:Gem::Dependency
|
79
|
-
name: minitest-fail-fast
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
81
|
-
requirements:
|
82
|
-
- - ">="
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
version: '0'
|
85
|
-
type: :development
|
86
|
-
prerelease: false
|
87
|
-
version_requirements: !ruby/object:Gem::Requirement
|
88
|
-
requirements:
|
89
|
-
- - ">="
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
version: '0'
|
92
|
-
- !ruby/object:Gem::Dependency
|
93
|
-
name: minitest-line
|
94
|
-
requirement: !ruby/object:Gem::Requirement
|
95
|
-
requirements:
|
96
|
-
- - ">="
|
97
|
-
- !ruby/object:Gem::Version
|
98
|
-
version: '0'
|
99
|
-
type: :development
|
100
|
-
prerelease: false
|
101
|
-
version_requirements: !ruby/object:Gem::Requirement
|
102
|
-
requirements:
|
103
|
-
- - ">="
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
version: '0'
|
106
|
-
- !ruby/object:Gem::Dependency
|
107
|
-
name: minitest-mock_expectations
|
108
|
-
requirement: !ruby/object:Gem::Requirement
|
109
|
-
requirements:
|
110
|
-
- - "~>"
|
111
|
-
- !ruby/object:Gem::Version
|
112
|
-
version: 1.1.3
|
113
|
-
type: :development
|
114
|
-
prerelease: false
|
115
|
-
version_requirements: !ruby/object:Gem::Requirement
|
116
|
-
requirements:
|
117
|
-
- - "~>"
|
118
|
-
- !ruby/object:Gem::Version
|
119
|
-
version: 1.1.3
|
120
|
-
- !ruby/object:Gem::Dependency
|
121
|
-
name: phenix
|
122
|
-
requirement: !ruby/object:Gem::Requirement
|
123
|
-
requirements:
|
124
|
-
- - ">="
|
125
|
-
- !ruby/object:Gem::Version
|
126
|
-
version: 1.0.1
|
127
|
-
type: :development
|
128
|
-
prerelease: false
|
129
|
-
version_requirements: !ruby/object:Gem::Requirement
|
130
|
-
requirements:
|
131
|
-
- - ">="
|
132
|
-
- !ruby/object:Gem::Version
|
133
|
-
version: 1.0.1
|
134
|
-
- !ruby/object:Gem::Dependency
|
135
|
-
name: pry-byebug
|
136
|
-
requirement: !ruby/object:Gem::Requirement
|
137
|
-
requirements:
|
138
|
-
- - "~>"
|
139
|
-
- !ruby/object:Gem::Version
|
140
|
-
version: '3.9'
|
141
|
-
type: :development
|
142
|
-
prerelease: false
|
143
|
-
version_requirements: !ruby/object:Gem::Requirement
|
144
|
-
requirements:
|
145
|
-
- - "~>"
|
146
|
-
- !ruby/object:Gem::Version
|
147
|
-
version: '3.9'
|
148
|
-
- !ruby/object:Gem::Dependency
|
149
|
-
name: rake
|
150
|
-
requirement: !ruby/object:Gem::Requirement
|
151
|
-
requirements:
|
152
|
-
- - ">="
|
153
|
-
- !ruby/object:Gem::Version
|
154
|
-
version: 12.0.0
|
155
|
-
type: :development
|
156
|
-
prerelease: false
|
157
|
-
version_requirements: !ruby/object:Gem::Requirement
|
158
|
-
requirements:
|
159
|
-
- - ">="
|
160
|
-
- !ruby/object:Gem::Version
|
161
|
-
version: 12.0.0
|
162
|
-
- !ruby/object:Gem::Dependency
|
163
|
-
name: rubocop
|
164
|
-
requirement: !ruby/object:Gem::Requirement
|
165
|
-
requirements:
|
166
|
-
- - "~>"
|
167
|
-
- !ruby/object:Gem::Version
|
168
|
-
version: 0.80.0
|
169
|
-
type: :development
|
170
|
-
prerelease: false
|
171
|
-
version_requirements: !ruby/object:Gem::Requirement
|
172
|
-
requirements:
|
173
|
-
- - "~>"
|
174
|
-
- !ruby/object:Gem::Version
|
175
|
-
version: 0.80.0
|
35
|
+
version: '7.2'
|
176
36
|
description: ''
|
177
37
|
email:
|
178
38
|
- bquorning@zendesk.com
|
@@ -184,6 +44,7 @@ extra_rdoc_files:
|
|
184
44
|
- MIT-LICENSE
|
185
45
|
- Readme.md
|
186
46
|
files:
|
47
|
+
- Changelog.md
|
187
48
|
- MIT-LICENSE
|
188
49
|
- Readme.md
|
189
50
|
- lib/active_record_host_pool.rb
|
@@ -191,13 +52,7 @@ files:
|
|
191
52
|
- lib/active_record_host_pool/connection_adapter_mixin.rb
|
192
53
|
- lib/active_record_host_pool/connection_proxy.rb
|
193
54
|
- lib/active_record_host_pool/pool_proxy.rb
|
194
|
-
- lib/active_record_host_pool/pool_proxy_6_1.rb
|
195
|
-
- lib/active_record_host_pool/pool_proxy_legacy.rb
|
196
55
|
- lib/active_record_host_pool/version.rb
|
197
|
-
- test/database.yml
|
198
|
-
- test/helper.rb
|
199
|
-
- test/schema.rb
|
200
|
-
- test/test_arhp.rb
|
201
56
|
homepage: https://github.com/zendesk/active_record_host_pool
|
202
57
|
licenses:
|
203
58
|
- MIT
|
@@ -210,20 +65,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
210
65
|
requirements:
|
211
66
|
- - ">="
|
212
67
|
- !ruby/object:Gem::Version
|
213
|
-
version: 2.
|
68
|
+
version: 2.7.0
|
214
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
215
70
|
requirements:
|
216
|
-
- - "
|
71
|
+
- - ">"
|
217
72
|
- !ruby/object:Gem::Version
|
218
|
-
version:
|
73
|
+
version: 1.3.1
|
219
74
|
requirements: []
|
220
75
|
rubygems_version: 3.0.3.1
|
221
76
|
signing_key:
|
222
77
|
specification_version: 4
|
223
78
|
summary: Allow ActiveRecord to share a connection to multiple databases on the same
|
224
79
|
host
|
225
|
-
test_files:
|
226
|
-
- test/database.yml
|
227
|
-
- test/helper.rb
|
228
|
-
- test/schema.rb
|
229
|
-
- test/test_arhp.rb
|
80
|
+
test_files: []
|
@@ -1,154 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'delegate'
|
4
|
-
require 'active_record'
|
5
|
-
require 'active_record_host_pool/connection_adapter_mixin'
|
6
|
-
|
7
|
-
# this module sits in between ConnectionHandler and a bunch of different ConnectionPools (one per host).
|
8
|
-
# when a connection is requested, it goes like:
|
9
|
-
# ActiveRecordClass -> ConnectionHandler#connection
|
10
|
-
# ConnectionHandler#connection -> (find or create PoolProxy)
|
11
|
-
# PoolProxy -> shared list of Pools
|
12
|
-
# Pool actually gives back a connection, then PoolProxy turns this
|
13
|
-
# into a ConnectionProxy that can inform (on execute) which db we should be on.
|
14
|
-
|
15
|
-
module ActiveRecordHostPool
|
16
|
-
# Sits between ConnectionHandler and a bunch of different ConnectionPools (one per host).
|
17
|
-
class PoolProxy < Delegator
|
18
|
-
def initialize(pool_config)
|
19
|
-
super(pool_config)
|
20
|
-
@pool_config = pool_config
|
21
|
-
@config = pool_config.db_config.configuration_hash
|
22
|
-
end
|
23
|
-
|
24
|
-
def __getobj__
|
25
|
-
_connection_pool
|
26
|
-
end
|
27
|
-
|
28
|
-
def __setobj__(pool_config)
|
29
|
-
@pool_config = pool_config
|
30
|
-
@config = pool_config.db_config.configuration_hash
|
31
|
-
@_pool_key = nil
|
32
|
-
end
|
33
|
-
|
34
|
-
attr_reader :pool_config
|
35
|
-
|
36
|
-
def connection(*args)
|
37
|
-
real_connection = _unproxied_connection(*args)
|
38
|
-
_connection_proxy_for(real_connection, @config[:database])
|
39
|
-
rescue Mysql2::Error, ActiveRecord::NoDatabaseError
|
40
|
-
_connection_pools.delete(_pool_key)
|
41
|
-
Kernel.raise
|
42
|
-
end
|
43
|
-
|
44
|
-
def _unproxied_connection(*args)
|
45
|
-
_connection_pool.connection(*args)
|
46
|
-
end
|
47
|
-
|
48
|
-
# by the time we are patched into ActiveRecord, the current thread has already established
|
49
|
-
# a connection. thus we need to patch both connection and checkout/checkin
|
50
|
-
def checkout(*args, &block)
|
51
|
-
cx = _connection_pool.checkout(*args, &block)
|
52
|
-
_connection_proxy_for(cx, @config[:database])
|
53
|
-
end
|
54
|
-
|
55
|
-
def checkin(cx)
|
56
|
-
cx = cx.unproxied
|
57
|
-
_connection_pool.checkin(cx)
|
58
|
-
end
|
59
|
-
|
60
|
-
def with_connection
|
61
|
-
cx = checkout
|
62
|
-
yield cx
|
63
|
-
ensure
|
64
|
-
checkin cx
|
65
|
-
end
|
66
|
-
|
67
|
-
def disconnect!
|
68
|
-
p = _connection_pool(false)
|
69
|
-
return unless p
|
70
|
-
|
71
|
-
p.disconnect!
|
72
|
-
p.automatic_reconnect = true if p.respond_to?(:automatic_reconnect=)
|
73
|
-
_clear_connection_proxy_cache
|
74
|
-
end
|
75
|
-
|
76
|
-
def automatic_reconnect=(value)
|
77
|
-
p = _connection_pool(false)
|
78
|
-
return unless p
|
79
|
-
|
80
|
-
p.automatic_reconnect = value if p.respond_to?(:automatic_reconnect=)
|
81
|
-
end
|
82
|
-
|
83
|
-
def clear_reloadable_connections!
|
84
|
-
_connection_pool.clear_reloadable_connections!
|
85
|
-
_clear_connection_proxy_cache
|
86
|
-
end
|
87
|
-
|
88
|
-
def release_connection(*args)
|
89
|
-
p = _connection_pool(false)
|
90
|
-
return unless p
|
91
|
-
|
92
|
-
p.release_connection(*args)
|
93
|
-
end
|
94
|
-
|
95
|
-
def flush!
|
96
|
-
p = _connection_pool(false)
|
97
|
-
return unless p
|
98
|
-
|
99
|
-
p.flush!
|
100
|
-
end
|
101
|
-
|
102
|
-
def discard!
|
103
|
-
p = _connection_pool(false)
|
104
|
-
return unless p
|
105
|
-
|
106
|
-
p.discard!
|
107
|
-
|
108
|
-
# All connections in the pool (even if they're currently
|
109
|
-
# leased!) have just been discarded, along with the pool itself.
|
110
|
-
# Any further interaction with the pool (except #pool_config and #schema_cache)
|
111
|
-
# is undefined.
|
112
|
-
# Remove the connection for the given key so a new one can be created in its place
|
113
|
-
_connection_pools.delete(_pool_key)
|
114
|
-
end
|
115
|
-
|
116
|
-
private
|
117
|
-
|
118
|
-
def _connection_pools
|
119
|
-
@@_connection_pools ||= {}
|
120
|
-
end
|
121
|
-
|
122
|
-
def _pool_key
|
123
|
-
@_pool_key ||= "#{@config[:host]}/#{@config[:port]}/#{@config[:socket]}/" \
|
124
|
-
"#{@config[:username]}/#{replica_configuration? && 'replica'}"
|
125
|
-
end
|
126
|
-
|
127
|
-
def _connection_pool(auto_create = true)
|
128
|
-
pool = _connection_pools[_pool_key]
|
129
|
-
if pool.nil? && auto_create
|
130
|
-
pool = _connection_pools[_pool_key] = ActiveRecord::ConnectionAdapters::ConnectionPool.new(@pool_config)
|
131
|
-
end
|
132
|
-
pool
|
133
|
-
end
|
134
|
-
|
135
|
-
def _connection_proxy_for(connection, database)
|
136
|
-
@connection_proxy_cache ||= {}
|
137
|
-
key = [connection, database]
|
138
|
-
|
139
|
-
@connection_proxy_cache[key] ||= begin
|
140
|
-
cx = ActiveRecordHostPool::ConnectionProxy.new(connection, database)
|
141
|
-
cx.execute('select 1')
|
142
|
-
cx
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
def _clear_connection_proxy_cache
|
147
|
-
@connection_proxy_cache = {}
|
148
|
-
end
|
149
|
-
|
150
|
-
def replica_configuration?
|
151
|
-
@config[:replica] || @config[:slave]
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
@@ -1,156 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# For versions of Rails < 6.1
|
4
|
-
|
5
|
-
require 'delegate'
|
6
|
-
require 'active_record'
|
7
|
-
require 'active_record_host_pool/connection_adapter_mixin'
|
8
|
-
|
9
|
-
# this module sits in between ConnectionHandler and a bunch of different ConnectionPools (one per host).
|
10
|
-
# when a connection is requested, it goes like:
|
11
|
-
# ActiveRecordClass -> ConnectionHandler#connection
|
12
|
-
# ConnectionHandler#connection -> (find or create PoolProxy)
|
13
|
-
# PoolProxy -> shared list of Pools
|
14
|
-
# Pool actually gives back a connection, then PoolProxy turns this
|
15
|
-
# into a ConnectionProxy that can inform (on execute) which db we should be on.
|
16
|
-
|
17
|
-
module ActiveRecordHostPool
|
18
|
-
# Sits between ConnectionHandler and a bunch of different ConnectionPools (one per host).
|
19
|
-
class PoolProxy < Delegator
|
20
|
-
def initialize(spec)
|
21
|
-
super(spec)
|
22
|
-
@spec = spec
|
23
|
-
@config = spec.config
|
24
|
-
end
|
25
|
-
|
26
|
-
def __getobj__
|
27
|
-
_connection_pool
|
28
|
-
end
|
29
|
-
|
30
|
-
def __setobj__(spec)
|
31
|
-
@spec = spec
|
32
|
-
@config = spec.config
|
33
|
-
@_pool_key = nil
|
34
|
-
end
|
35
|
-
|
36
|
-
attr_reader :spec
|
37
|
-
|
38
|
-
def connection(*args)
|
39
|
-
real_connection = _unproxied_connection(*args)
|
40
|
-
_connection_proxy_for(real_connection, @config[:database])
|
41
|
-
rescue Mysql2::Error, ActiveRecord::NoDatabaseError
|
42
|
-
_connection_pools.delete(_pool_key)
|
43
|
-
Kernel.raise
|
44
|
-
end
|
45
|
-
|
46
|
-
def _unproxied_connection(*args)
|
47
|
-
_connection_pool.connection(*args)
|
48
|
-
end
|
49
|
-
|
50
|
-
# by the time we are patched into ActiveRecord, the current thread has already established
|
51
|
-
# a connection. thus we need to patch both connection and checkout/checkin
|
52
|
-
def checkout(*args, &block)
|
53
|
-
cx = _connection_pool.checkout(*args, &block)
|
54
|
-
_connection_proxy_for(cx, @config[:database])
|
55
|
-
end
|
56
|
-
|
57
|
-
def checkin(cx)
|
58
|
-
cx = cx.unproxied
|
59
|
-
_connection_pool.checkin(cx)
|
60
|
-
end
|
61
|
-
|
62
|
-
def with_connection
|
63
|
-
cx = checkout
|
64
|
-
yield cx
|
65
|
-
ensure
|
66
|
-
checkin cx
|
67
|
-
end
|
68
|
-
|
69
|
-
def disconnect!
|
70
|
-
p = _connection_pool(false)
|
71
|
-
return unless p
|
72
|
-
|
73
|
-
p.disconnect!
|
74
|
-
p.automatic_reconnect = true if p.respond_to?(:automatic_reconnect=)
|
75
|
-
_clear_connection_proxy_cache
|
76
|
-
end
|
77
|
-
|
78
|
-
def automatic_reconnect=(value)
|
79
|
-
p = _connection_pool(false)
|
80
|
-
return unless p
|
81
|
-
|
82
|
-
p.automatic_reconnect = value if p.respond_to?(:automatic_reconnect=)
|
83
|
-
end
|
84
|
-
|
85
|
-
def clear_reloadable_connections!
|
86
|
-
_connection_pool.clear_reloadable_connections!
|
87
|
-
_clear_connection_proxy_cache
|
88
|
-
end
|
89
|
-
|
90
|
-
def release_connection(*args)
|
91
|
-
p = _connection_pool(false)
|
92
|
-
return unless p
|
93
|
-
|
94
|
-
p.release_connection(*args)
|
95
|
-
end
|
96
|
-
|
97
|
-
def flush!
|
98
|
-
p = _connection_pool(false)
|
99
|
-
return unless p
|
100
|
-
|
101
|
-
p.flush!
|
102
|
-
end
|
103
|
-
|
104
|
-
def discard!
|
105
|
-
p = _connection_pool(false)
|
106
|
-
return unless p
|
107
|
-
|
108
|
-
p.discard!
|
109
|
-
|
110
|
-
# All connections in the pool (even if they're currently
|
111
|
-
# leased!) have just been discarded, along with the pool itself.
|
112
|
-
# Any further interaction with the pool (except #spec and #schema_cache)
|
113
|
-
# is undefined.
|
114
|
-
# Remove the connection for the given key so a new one can be created in its place
|
115
|
-
_connection_pools.delete(_pool_key)
|
116
|
-
end
|
117
|
-
|
118
|
-
private
|
119
|
-
|
120
|
-
def _connection_pools
|
121
|
-
@@_connection_pools ||= {}
|
122
|
-
end
|
123
|
-
|
124
|
-
def _pool_key
|
125
|
-
@_pool_key ||= "#{@config[:host]}/#{@config[:port]}/#{@config[:socket]}/" \
|
126
|
-
"#{@config[:username]}/#{replica_configuration? && 'replica'}"
|
127
|
-
end
|
128
|
-
|
129
|
-
def _connection_pool(auto_create = true)
|
130
|
-
pool = _connection_pools[_pool_key]
|
131
|
-
if pool.nil? && auto_create
|
132
|
-
pool = _connection_pools[_pool_key] = ActiveRecord::ConnectionAdapters::ConnectionPool.new(@spec)
|
133
|
-
end
|
134
|
-
pool
|
135
|
-
end
|
136
|
-
|
137
|
-
def _connection_proxy_for(connection, database)
|
138
|
-
@connection_proxy_cache ||= {}
|
139
|
-
key = [connection, database]
|
140
|
-
|
141
|
-
@connection_proxy_cache[key] ||= begin
|
142
|
-
cx = ActiveRecordHostPool::ConnectionProxy.new(connection, database)
|
143
|
-
cx.execute('select 1')
|
144
|
-
cx
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
def _clear_connection_proxy_cache
|
149
|
-
@connection_proxy_cache = {}
|
150
|
-
end
|
151
|
-
|
152
|
-
def replica_configuration?
|
153
|
-
@config[:replica] || @config[:slave]
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
data/test/database.yml
DELETED
@@ -1,108 +0,0 @@
|
|
1
|
-
<% mysql = URI(ENV['MYSQL_URL'] || 'mysql://root@127.0.0.1:3306') %>
|
2
|
-
# ARHP creates separate connection pools based on the pool key.
|
3
|
-
# The pool key is defined as:
|
4
|
-
# host / port / socket / username / replica
|
5
|
-
#
|
6
|
-
# Therefore two databases with identical host, port, socket, username, and replica status will share a connection pool.
|
7
|
-
# If any part (host, port, etc.) of the pool key differ, two databases will _not_ share a connection pool.
|
8
|
-
#
|
9
|
-
# Below, "test_pool_1..." and "test_pool_2..." have identical host, username, socket, and replica status but the port information differs.
|
10
|
-
# Here the yml configurations are reformatted as a table to give a visual example:
|
11
|
-
#
|
12
|
-
# |----------+----------------+----------------|
|
13
|
-
# | | test_pool_1 | test_pool_2 |
|
14
|
-
# |----------+----------------+----------------+
|
15
|
-
# | host | 127.0.0.1 | 127.0.0.1 |
|
16
|
-
# | port | | 3306 |
|
17
|
-
# | socket | | |
|
18
|
-
# | username | root | root |
|
19
|
-
# | replica | false | false |
|
20
|
-
# |----------+----------------+----------------|
|
21
|
-
#
|
22
|
-
# Note: The configuration items must be explicitly defined or will be blank in the pool key.
|
23
|
-
# Configurations with matching _implicit_ items but differing _explicit_ items will create separate pools.
|
24
|
-
# e.g. "test_pool_1" will default to port 3306 but because it is not explicitly defined it will not share a pool with test_pool_2
|
25
|
-
#
|
26
|
-
# ARHP will therefore create the following pool keys:
|
27
|
-
# test_pool_1 => 127.0.0.1///root/false
|
28
|
-
# test_pool_2 => 127.0.0.1/3306//root/false
|
29
|
-
|
30
|
-
test_pool_1_db_a:
|
31
|
-
adapter: mysql2
|
32
|
-
encoding: utf8
|
33
|
-
database: arhp_test_db_a
|
34
|
-
username: <%= mysql.user %>
|
35
|
-
password: <%= mysql.password %>
|
36
|
-
host: <%= mysql.host %>
|
37
|
-
reconnect: true
|
38
|
-
|
39
|
-
# Mimic configurations as read by active_record_shards/ar_flexmaster
|
40
|
-
test_pool_1_db_a_replica:
|
41
|
-
adapter: mysql2
|
42
|
-
encoding: utf8
|
43
|
-
database: arhp_test_db_a_replica
|
44
|
-
username: <%= mysql.user %>
|
45
|
-
password: <%= mysql.password %>
|
46
|
-
host: <%= mysql.host %>
|
47
|
-
reconnect: true
|
48
|
-
slave: true
|
49
|
-
|
50
|
-
test_pool_1_db_b:
|
51
|
-
adapter: mysql2
|
52
|
-
encoding: utf8
|
53
|
-
database: arhp_test_db_b
|
54
|
-
username: <%= mysql.user %>
|
55
|
-
password: <%= mysql.password %>
|
56
|
-
host: <%= mysql.host %>
|
57
|
-
reconnect: true
|
58
|
-
|
59
|
-
test_pool_1_db_not_there:
|
60
|
-
adapter: mysql2
|
61
|
-
encoding: utf8
|
62
|
-
database: arhp_test_db_not_there
|
63
|
-
username: <%= mysql.user %>
|
64
|
-
password: <%= mysql.password %>
|
65
|
-
host: <%= mysql.host %>
|
66
|
-
reconnect: true
|
67
|
-
|
68
|
-
test_pool_2_db_d:
|
69
|
-
adapter: mysql2
|
70
|
-
encoding: utf8
|
71
|
-
database: arhp_test_db_d
|
72
|
-
username: <%= mysql.user %>
|
73
|
-
password: <%= mysql.password %>
|
74
|
-
host: <%= mysql.host %>
|
75
|
-
port: <%= mysql.port %>
|
76
|
-
reconnect: true
|
77
|
-
|
78
|
-
test_pool_2_db_e:
|
79
|
-
adapter: mysql2
|
80
|
-
encoding: utf8
|
81
|
-
database: arhp_test_db_e
|
82
|
-
username: <%= mysql.user %>
|
83
|
-
password: <%= mysql.password %>
|
84
|
-
host: <%= mysql.host %>
|
85
|
-
port: <%= mysql.port %>
|
86
|
-
reconnect: true
|
87
|
-
|
88
|
-
test_pool_3_db_e:
|
89
|
-
adapter: mysql2
|
90
|
-
encoding: utf8
|
91
|
-
database: arhp_test_db_e
|
92
|
-
username: john-doe
|
93
|
-
password:
|
94
|
-
host: <%= mysql.host %>
|
95
|
-
port: <%= mysql.port %>
|
96
|
-
reconnect: true
|
97
|
-
|
98
|
-
# test_pool_1_db_c needs to be the last database defined in the file
|
99
|
-
# otherwise the test_models_with_matching_hosts_and_non_matching_databases_issue_exists_without_arhp_patch
|
100
|
-
# test fails
|
101
|
-
test_pool_1_db_c:
|
102
|
-
adapter: mysql2
|
103
|
-
encoding: utf8
|
104
|
-
database: arhp_test_db_c
|
105
|
-
username: <%= mysql.user %>
|
106
|
-
password: <%= mysql.password %>
|
107
|
-
host: <%= mysql.host %>
|
108
|
-
reconnect: true
|