active_record_shards 5.2.0 → 5.3.1
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/lib/active_record_shards/connection_switcher.rb +31 -4
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 032e2279ef2f82d2a1a30a171429a7b34b625766fe3a6060ad21141d551c0ca4
|
4
|
+
data.tar.gz: 169c3f8e0bf7d4f036a23106d8523b5e09756535f289be4da5ec295ec6c1605d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c35a082c7b33926009467f10871177ecb02a2c5dc3b009a1f5d1a889fb49f039ea88bb931cdd80c7cc67763120158748610925ece6d53ee463020388a4690cc5
|
7
|
+
data.tar.gz: 4acc42ae93f573d60d12384f6f7454b4a85d1a5a13239491cb6b00a10d722dfb1534026119f845b3f8c39c5e0114500099eac6806cc2c8b6864c7c9f74835fde
|
@@ -4,6 +4,8 @@ require 'active_record_shards/shard_support'
|
|
4
4
|
|
5
5
|
module ActiveRecordShards
|
6
6
|
module ConnectionSwitcher
|
7
|
+
class LegacyConnectionHandlingError < StandardError; end
|
8
|
+
|
7
9
|
case "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"
|
8
10
|
when '6.1', '7.0'
|
9
11
|
SHARD_NAMES_CONFIG_KEY = :shard_names
|
@@ -96,10 +98,9 @@ module ActiveRecordShards
|
|
96
98
|
end
|
97
99
|
|
98
100
|
def on_cx_switch_block(which, force: false, construct_ro_scope: nil, &block)
|
99
|
-
|
100
|
-
@disallow_replica += 1 if which == :primary
|
101
|
+
self.disallow_replica += 1 if which == :primary
|
101
102
|
|
102
|
-
switch_to_replica = force ||
|
103
|
+
switch_to_replica = force || disallow_replica.zero?
|
103
104
|
old_options = current_shard_selection.options
|
104
105
|
|
105
106
|
switch_connection(replica: switch_to_replica)
|
@@ -112,10 +113,18 @@ module ActiveRecordShards
|
|
112
113
|
readonly.scoping(&block)
|
113
114
|
end
|
114
115
|
ensure
|
115
|
-
|
116
|
+
self.disallow_replica -= 1 if which == :primary
|
116
117
|
switch_connection(old_options) if old_options
|
117
118
|
end
|
118
119
|
|
120
|
+
def disallow_replica=(value)
|
121
|
+
Thread.current[:__active_record_shards__disallow_replica_by_thread] = value
|
122
|
+
end
|
123
|
+
|
124
|
+
def disallow_replica
|
125
|
+
Thread.current[:__active_record_shards__disallow_replica_by_thread] ||= 0
|
126
|
+
end
|
127
|
+
|
119
128
|
def supports_sharding?
|
120
129
|
shard_names.any?
|
121
130
|
end
|
@@ -163,6 +172,8 @@ module ActiveRecordShards
|
|
163
172
|
alias_method :check_config_for_env, :config_for_env
|
164
173
|
|
165
174
|
def switch_connection(options)
|
175
|
+
ensure_legacy_connection_handling if ActiveRecord.version >= Gem::Version.new('6.1')
|
176
|
+
|
166
177
|
if options.any?
|
167
178
|
if options.key?(:replica)
|
168
179
|
current_shard_selection.on_replica = options[:replica]
|
@@ -178,6 +189,22 @@ module ActiveRecordShards
|
|
178
189
|
end
|
179
190
|
end
|
180
191
|
|
192
|
+
def ensure_legacy_connection_handling
|
193
|
+
unless legacy_connection_handling_owner.legacy_connection_handling
|
194
|
+
raise LegacyConnectionHandlingError, "ActiveRecordShards is _only_ compatible with ActiveRecord `legacy_connection_handling` set to `true`."
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def legacy_connection_handling_owner
|
199
|
+
@legacy_connection_handling_owner ||=
|
200
|
+
case "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"
|
201
|
+
when '7.0'
|
202
|
+
ActiveRecord
|
203
|
+
when '6.1'
|
204
|
+
ActiveRecord::Base
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
181
208
|
def shard_env
|
182
209
|
ActiveRecordShards.app_env
|
183
210
|
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: 5.
|
4
|
+
version: 5.3.1
|
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:
|
16
|
+
date: 2023-02-14 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: activerecord
|
@@ -97,20 +97,6 @@ dependencies:
|
|
97
97
|
- - ">="
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: '0'
|
100
|
-
- !ruby/object:Gem::Dependency
|
101
|
-
name: mocha
|
102
|
-
requirement: !ruby/object:Gem::Requirement
|
103
|
-
requirements:
|
104
|
-
- - ">="
|
105
|
-
- !ruby/object:Gem::Version
|
106
|
-
version: 1.4.0
|
107
|
-
type: :development
|
108
|
-
prerelease: false
|
109
|
-
version_requirements: !ruby/object:Gem::Requirement
|
110
|
-
requirements:
|
111
|
-
- - ">="
|
112
|
-
- !ruby/object:Gem::Version
|
113
|
-
version: 1.4.0
|
114
100
|
- !ruby/object:Gem::Dependency
|
115
101
|
name: mysql2
|
116
102
|
requirement: !ruby/object:Gem::Requirement
|