active_record_shards 5.4.0 → 5.5.0
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: f9e4c9f26a03dde94772c0888e49e3af56d68ffc4576fff3123a8dd50a73cce7
|
4
|
+
data.tar.gz: d4ea926bf565928ac2873e02b08b481cf731d3d62483482de450137886505d4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 699945070cfc1dde026841e71489a1e3d9e743cb4b49ff8e9a5f0849c1f50f3a55dab9833614377b8a998b8b181755c0efd2d090d3acd1d0f180c7dffee69c03
|
7
|
+
data.tar.gz: 6c1d7c1eb206352102e9d13b2f045e4e9cbd7262f8fe6baab0218ad9273e0ecab21442900730d8b1b07754b65e15d07f7341415f495930265ff892e455eb73c7
|
@@ -7,6 +7,10 @@ module ActiveRecordShards
|
|
7
7
|
class LegacyConnectionHandlingError < StandardError; end
|
8
8
|
class IsolationLevelError < StandardError; end
|
9
9
|
|
10
|
+
Thread.attr_accessor :_active_record_shards_disallow_replica_by_thread,
|
11
|
+
:_active_record_shards_in_migration,
|
12
|
+
:_active_record_shards_shard_selection
|
13
|
+
|
10
14
|
case "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"
|
11
15
|
when '6.1', '7.0'
|
12
16
|
SHARD_NAMES_CONFIG_KEY = :shard_names
|
@@ -20,6 +24,9 @@ module ActiveRecordShards
|
|
20
24
|
|
21
25
|
base.singleton_class.send(:alias_method, :table_exists_without_default_shard?, :table_exists?)
|
22
26
|
base.singleton_class.send(:alias_method, :table_exists?, :table_exists_with_default_shard?)
|
27
|
+
|
28
|
+
base.singleton_class.send(:alias_method, :reset_primary_key_without_default_shard, :reset_primary_key)
|
29
|
+
base.singleton_class.send(:alias_method, :reset_primary_key, :reset_primary_key_with_default_shard)
|
23
30
|
end
|
24
31
|
|
25
32
|
def on_primary_db(&block)
|
@@ -119,11 +126,11 @@ module ActiveRecordShards
|
|
119
126
|
end
|
120
127
|
|
121
128
|
def disallow_replica=(value)
|
122
|
-
Thread.current
|
129
|
+
Thread.current._active_record_shards_disallow_replica_by_thread = value
|
123
130
|
end
|
124
131
|
|
125
132
|
def disallow_replica
|
126
|
-
Thread.current
|
133
|
+
Thread.current._active_record_shards_disallow_replica_by_thread ||= 0
|
127
134
|
end
|
128
135
|
|
129
136
|
def supports_sharding?
|
@@ -135,8 +142,7 @@ module ActiveRecordShards
|
|
135
142
|
end
|
136
143
|
|
137
144
|
def current_shard_selection
|
138
|
-
|
139
|
-
Thread.current.thread_variable_set(:shard_selection, cs)
|
145
|
+
Thread.current._active_record_shards_shard_selection ||= ShardSelection.new
|
140
146
|
end
|
141
147
|
|
142
148
|
def current_shard_id
|
@@ -147,6 +153,10 @@ module ActiveRecordShards
|
|
147
153
|
config_for_env[SHARD_NAMES_CONFIG_KEY] || []
|
148
154
|
end
|
149
155
|
|
156
|
+
def reset_primary_key_with_default_shard
|
157
|
+
with_default_shard { reset_primary_key_without_default_shard }
|
158
|
+
end
|
159
|
+
|
150
160
|
private
|
151
161
|
|
152
162
|
def config_for_env
|
@@ -69,7 +69,7 @@ module ActiveRecordShards
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def on_replica_unless_tx(&block)
|
72
|
-
return yield if Thread.current
|
72
|
+
return yield if Thread.current._active_record_shards_in_migration
|
73
73
|
return yield if _in_transaction?
|
74
74
|
|
75
75
|
if on_replica_by_default?
|
@@ -84,7 +84,7 @@ module ActiveRecordShards
|
|
84
84
|
end
|
85
85
|
|
86
86
|
def force_on_replica(&block)
|
87
|
-
return yield if Thread.current
|
87
|
+
return yield if Thread.current._active_record_shards_in_migration
|
88
88
|
|
89
89
|
on_cx_switch_block(:replica, construct_ro_scope: false, force: true, &block)
|
90
90
|
end
|
@@ -105,7 +105,7 @@ module ActiveRecordShards
|
|
105
105
|
|
106
106
|
module Rails52RelationPatches
|
107
107
|
def connection
|
108
|
-
return super if Thread.current
|
108
|
+
return super if Thread.current._active_record_shards_in_migration
|
109
109
|
return super if _in_transaction?
|
110
110
|
|
111
111
|
if @klass.on_replica_by_default?
|
@@ -197,7 +197,7 @@ module ActiveRecordShards
|
|
197
197
|
|
198
198
|
module TypeCasterConnectionConnectionPatch
|
199
199
|
def connection
|
200
|
-
return super if Thread.current
|
200
|
+
return super if Thread.current._active_record_shards_in_migration
|
201
201
|
return super if ActiveRecord::Base._in_transaction?
|
202
202
|
|
203
203
|
if @klass.on_replica_by_default?
|
@@ -210,11 +210,11 @@ module ActiveRecordShards
|
|
210
210
|
|
211
211
|
module SchemaDefinePatch
|
212
212
|
def define(info, &block)
|
213
|
-
old_val = Thread.current
|
214
|
-
Thread.current
|
213
|
+
old_val = Thread.current._active_record_shards_in_migration
|
214
|
+
Thread.current._active_record_shards_in_migration = true
|
215
215
|
super
|
216
216
|
ensure
|
217
|
-
Thread.current
|
217
|
+
Thread.current._active_record_shards_in_migration = old_val
|
218
218
|
end
|
219
219
|
end
|
220
220
|
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.5.0
|
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-08-
|
16
|
+
date: 2023-08-26 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: activerecord
|