active_record_shards 5.3.1 → 5.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_record_shards/connection_switcher.rb +8 -4
- data/lib/active_record_shards/model.rb +12 -9
- data/lib/active_record_shards.rb +19 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e71e05125d6c15ad696e8243cb09234c09d29e1c381b47adeee2a81b0b79e188
|
4
|
+
data.tar.gz: f06e143aabfc0e14d3058e03acc367e54d0219bcbf9355df57ee33e174393dbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60629cde5e087c941d9ce3d753a57c5d73f37cbd78d9e7b0f6f1d921834c25267371a0b2e957a92112eac3f295a837a2a41681cda63dc3a6bfd981811dfbcd91
|
7
|
+
data.tar.gz: 2c4e012130eead2088089cefb2204508141b3bd5056f733ccd26029fa053ae78b10b077750b64f5b364731b752842210086e368f813b3b1b333e9cdf2fecefb9
|
@@ -142,10 +142,6 @@ module ActiveRecordShards
|
|
142
142
|
end
|
143
143
|
|
144
144
|
def shard_names
|
145
|
-
unless config_for_env.fetch(SHARD_NAMES_CONFIG_KEY, []).all? { |shard_name| shard_name.is_a?(Integer) }
|
146
|
-
raise "All shard names must be integers: #{config_for_env[SHARD_NAMES_CONFIG_KEY].inspect}."
|
147
|
-
end
|
148
|
-
|
149
145
|
config_for_env[SHARD_NAMES_CONFIG_KEY] || []
|
150
146
|
end
|
151
147
|
|
@@ -166,11 +162,19 @@ module ActiveRecordShards
|
|
166
162
|
raise "Did not find #{shard_env} in configurations, did you forget to add it to your database config? (configurations: #{configurations.to_h.keys.inspect})"
|
167
163
|
end
|
168
164
|
|
165
|
+
ensure_all_shard_names_are_integers(config)
|
166
|
+
|
169
167
|
config
|
170
168
|
end
|
171
169
|
end
|
172
170
|
alias_method :check_config_for_env, :config_for_env
|
173
171
|
|
172
|
+
def ensure_all_shard_names_are_integers(config)
|
173
|
+
unless config.fetch(SHARD_NAMES_CONFIG_KEY, []).all? { |shard_name| shard_name.is_a?(Integer) }
|
174
|
+
raise "All shard names must be integers: #{config.inspect}."
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
174
178
|
def switch_connection(options)
|
175
179
|
ensure_legacy_connection_handling if ActiveRecord.version >= Gem::Version.new('6.1')
|
176
180
|
|
@@ -11,17 +11,20 @@ module ActiveRecordShards
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def is_sharded? # rubocop:disable Naming/PredicateName
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
if
|
18
|
-
|
14
|
+
return @_ars_model_is_sharded unless @_ars_model_is_sharded.nil?
|
15
|
+
|
16
|
+
@_ars_model_is_sharded =
|
17
|
+
if self == ActiveRecord::Base
|
18
|
+
sharded != false && supports_sharding?
|
19
|
+
elsif self == base_class
|
20
|
+
if sharded.nil?
|
21
|
+
ActiveRecord::Base.is_sharded?
|
22
|
+
else
|
23
|
+
sharded != false
|
24
|
+
end
|
19
25
|
else
|
20
|
-
|
26
|
+
base_class.is_sharded?
|
21
27
|
end
|
22
|
-
else
|
23
|
-
base_class.is_sharded?
|
24
|
-
end
|
25
28
|
end
|
26
29
|
|
27
30
|
def on_replica_by_default?
|
data/lib/active_record_shards.rb
CHANGED
@@ -18,12 +18,25 @@ module ActiveRecordShards
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.app_env
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
@app_env ||= begin
|
22
|
+
env = Rails.env if defined?(Rails.env)
|
23
|
+
env ||= RAILS_ENV if Object.const_defined?(:RAILS_ENV)
|
24
|
+
env ||= ENV['RAILS_ENV']
|
25
|
+
env ||= APP_ENV if Object.const_defined?(:APP_ENV)
|
26
|
+
env ||= ENV['APP_ENV']
|
27
|
+
env || 'development'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Busts internal caches kept by active_record_shards, for things which are _supposed_ to be the
|
32
|
+
# same for the life of the process. You shouldn't need to call this unless you're doing something
|
33
|
+
# truly evil like changing RAILS_ENV after boot
|
34
|
+
def self.reset_app_env!
|
35
|
+
@app_env = nil
|
36
|
+
models = [ActiveRecord::Base] + ActiveRecord::Base.descendants
|
37
|
+
models.each do |model|
|
38
|
+
model.remove_instance_variable(:@_ars_model_is_sharded) if model.instance_variable_defined?(:@_ars_model_is_sharded)
|
39
|
+
end
|
27
40
|
end
|
28
41
|
end
|
29
42
|
|
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: 5.3.
|
4
|
+
version: 5.3.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: 2023-
|
16
|
+
date: 2023-04-28 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: activerecord
|