active_record_shards 3.19.2 → 3.19.3
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a4987e63e2554b3570cdc243b569b292ff6d9d7c0821ebeeb78768e244e8c93
|
4
|
+
data.tar.gz: fccba58bc0876d615dfbe62b4a14486dac3bf67eefd2614da23363ea52f7519b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9344f045cce08fad0308aa7767d3581e527fd2afd6897c9ae50461070e9e730c4a392ab9a9c47218cf5cc36f2d26afd0aadebea922bbd5f3c0724ada3a50c182
|
7
|
+
data.tar.gz: fc6f5e72ccb01955d028796c53d389a472d3157f05a1350a5c9c200714a48cc67ceb57f1def6d6e8be0fb5187ffb676cef855ea428f3c3042b6165a3ff72a2a5
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module ActiveRecordShards
|
2
|
+
module ConnectionSwitcher
|
3
|
+
def connection_specification_name
|
4
|
+
name = current_shard_selection.resolve_connection_name(sharded: is_sharded?, configurations: configurations)
|
5
|
+
|
6
|
+
@_ars_connection_specification_names ||= {}
|
7
|
+
unless @_ars_connection_specification_names.include?(name)
|
8
|
+
unless configurations[name] || name == "primary"
|
9
|
+
raise ActiveRecord::AdapterNotSpecified, "No database defined by #{name} in your database config. (configurations: #{configurations.to_h.keys.inspect})"
|
10
|
+
end
|
11
|
+
|
12
|
+
@_ars_connection_specification_names[name] = true
|
13
|
+
end
|
14
|
+
|
15
|
+
name
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def ensure_shard_connection
|
21
|
+
# See if we've connected before. If not, call `#establish_connection`
|
22
|
+
# so that ActiveRecord can resolve connection_specification_name to an
|
23
|
+
# ARS connection.
|
24
|
+
spec_name = connection_specification_name
|
25
|
+
|
26
|
+
pool = connection_handler.retrieve_connection_pool(spec_name)
|
27
|
+
connection_handler.establish_connection(spec_name.to_sym) if pool.nil?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -153,18 +153,27 @@ module ActiveRecordShards
|
|
153
153
|
end
|
154
154
|
|
155
155
|
def shard_names
|
156
|
-
unless
|
157
|
-
raise "
|
158
|
-
end
|
159
|
-
unless config.fetch(SHARD_NAMES_CONFIG_KEY, []).all? { |shard_name| shard_name.is_a?(Integer) }
|
160
|
-
raise "All shard names must be integers: #{config[SHARD_NAMES_CONFIG_KEY].inspect}."
|
156
|
+
unless config_for_env.fetch(SHARD_NAMES_CONFIG_KEY, []).all? { |shard_name| shard_name.is_a?(Integer) }
|
157
|
+
raise "All shard names must be integers: #{config_for_env[SHARD_NAMES_CONFIG_KEY].inspect}."
|
161
158
|
end
|
162
159
|
|
163
|
-
|
160
|
+
config_for_env[SHARD_NAMES_CONFIG_KEY] || []
|
164
161
|
end
|
165
162
|
|
166
163
|
private
|
167
164
|
|
165
|
+
def config_for_env
|
166
|
+
@_ars_config_for_env ||= {}
|
167
|
+
@_ars_config_for_env[shard_env] ||= begin
|
168
|
+
unless config = configurations[shard_env]
|
169
|
+
raise "Did not find #{shard_env} in configurations, did you forget to add it to your database config? (configurations: #{configurations.to_h.keys.inspect})"
|
170
|
+
end
|
171
|
+
|
172
|
+
config
|
173
|
+
end
|
174
|
+
end
|
175
|
+
alias_method :check_config_for_env, :config_for_env
|
176
|
+
|
168
177
|
def switch_connection(options)
|
169
178
|
if options.any?
|
170
179
|
if options.key?(:replica)
|
@@ -172,9 +181,7 @@ module ActiveRecordShards
|
|
172
181
|
end
|
173
182
|
|
174
183
|
if options.key?(:shard)
|
175
|
-
|
176
|
-
raise "Did not find #{shard_env} in configurations, did you forget to add it to your database config? (configurations: #{configurations.to_h.keys.inspect})"
|
177
|
-
end
|
184
|
+
check_config_for_env
|
178
185
|
|
179
186
|
current_shard_selection.shard = options[:shard]
|
180
187
|
end
|
@@ -231,8 +238,10 @@ when '4.2'
|
|
231
238
|
require 'active_record_shards/connection_switcher-4-2'
|
232
239
|
when '5.0'
|
233
240
|
require 'active_record_shards/connection_switcher-5-0'
|
234
|
-
when '5.1', '5.2'
|
241
|
+
when '5.1', '5.2'
|
235
242
|
require 'active_record_shards/connection_switcher-5-1'
|
243
|
+
when '6.0'
|
244
|
+
require 'active_record_shards/connection_switcher-6-0'
|
236
245
|
else
|
237
246
|
raise "ActiveRecordShards is not compatible with #{ActiveRecord::VERSION::STRING}"
|
238
247
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_shards
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.19.
|
4
|
+
version: 3.19.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Quorning
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2022-
|
16
|
+
date: 2022-03-04 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: activerecord
|
@@ -201,6 +201,7 @@ files:
|
|
201
201
|
- lib/active_record_shards/connection_switcher-4-2.rb
|
202
202
|
- lib/active_record_shards/connection_switcher-5-0.rb
|
203
203
|
- lib/active_record_shards/connection_switcher-5-1.rb
|
204
|
+
- lib/active_record_shards/connection_switcher-6-0.rb
|
204
205
|
- lib/active_record_shards/connection_switcher.rb
|
205
206
|
- lib/active_record_shards/default_replica_patches.rb
|
206
207
|
- lib/active_record_shards/default_slave_patches.rb
|