switchman 3.1.1 → 3.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/switchman/active_record/base.rb +24 -0
- data/lib/switchman/active_record/migration.rb +8 -6
- data/lib/switchman/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb62453808b659106e48a2279bdabeb2901c97187eaf8ae6cd612d460096f6d0
|
4
|
+
data.tar.gz: 5cf42b899e7a63f73bf5604247a8e2b2cd4a998bd7f4f0986180e451e66d3cc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69d3bb8a559d81a5cb5ef81c7c19395c3eab13a9a53a0bd920ea715b822cde6256a2464f317a6f719c04c8f9baf99b751b6abb07ae6edda40055cd53b32c5a30
|
7
|
+
data.tar.gz: e16d69bb4d2ec76fbe198a8d0d68e4217f3b2a261eff1fcde61b82357374f5c1b029e28f9ec852c090196461d2f45d162bc0c420182ccf0d3b7a4869f4ff5263
|
@@ -138,9 +138,33 @@ module Switchman
|
|
138
138
|
else
|
139
139
|
Shard.current(self.class.connection_class_for_self)
|
140
140
|
end
|
141
|
+
readonly! if shadow_record?
|
141
142
|
super
|
142
143
|
end
|
143
144
|
|
145
|
+
def shadow_record?
|
146
|
+
pkey = self[self.class.primary_key]
|
147
|
+
return false unless self.class.sharded_column?(self.class.primary_key) && pkey
|
148
|
+
|
149
|
+
pkey > Shard::IDS_PER_SHARD
|
150
|
+
end
|
151
|
+
|
152
|
+
def save_shadow_record(new_attrs: attributes, target_shard: Shard.current)
|
153
|
+
return if target_shard == shard
|
154
|
+
|
155
|
+
shadow_attrs = {}
|
156
|
+
new_attrs.each do |attr, value|
|
157
|
+
shadow_attrs[attr] = if self.class.sharded_column?(attr)
|
158
|
+
Shard.relative_id_for(value, shard, target_shard)
|
159
|
+
else
|
160
|
+
value
|
161
|
+
end
|
162
|
+
end
|
163
|
+
target_shard.activate do
|
164
|
+
self.class.upsert(shadow_attrs, unique_by: self.class.primary_key)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
144
168
|
def shard
|
145
169
|
@shard || Shard.current(self.class.connection_class_for_self) || Shard.default
|
146
170
|
end
|
@@ -20,13 +20,15 @@ module Switchman
|
|
20
20
|
end
|
21
21
|
|
22
22
|
module Migrator
|
23
|
-
# significant change:
|
24
|
-
#
|
25
|
-
# name you're accessing may not be consistent
|
26
|
-
# to run migrations against multiple shards in the same database
|
27
|
-
# concurrently
|
23
|
+
# significant change: use the shard name instead of the database name
|
24
|
+
# in the lock id. Especially if you're going through pgbouncer, the
|
25
|
+
# database name you're accessing may not be consistent
|
28
26
|
def generate_migrator_advisory_lock_id
|
29
|
-
|
27
|
+
db_name_hash = Zlib.crc32(Shard.current.name)
|
28
|
+
shard_name_hash = ::ActiveRecord::Migrator::MIGRATOR_SALT * db_name_hash
|
29
|
+
# Store in internalmetadata to allow other tools to be able to lock out migrations
|
30
|
+
::ActiveRecord::InternalMetadata[:migrator_advisory_lock_id] = shard_name_hash
|
31
|
+
shard_name_hash
|
30
32
|
end
|
31
33
|
|
32
34
|
# significant change: strip out prefer_secondary from config
|
data/lib/switchman/version.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: switchman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cody Cutrer
|
8
8
|
- James Williams
|
9
9
|
- Jacob Fugal
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-
|
13
|
+
date: 2022-07-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -300,7 +300,7 @@ licenses:
|
|
300
300
|
- MIT
|
301
301
|
metadata:
|
302
302
|
rubygems_mfa_required: 'true'
|
303
|
-
post_install_message:
|
303
|
+
post_install_message:
|
304
304
|
rdoc_options: []
|
305
305
|
require_paths:
|
306
306
|
- lib
|
@@ -316,7 +316,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
316
316
|
version: '0'
|
317
317
|
requirements: []
|
318
318
|
rubygems_version: 3.1.6
|
319
|
-
signing_key:
|
319
|
+
signing_key:
|
320
320
|
specification_version: 4
|
321
321
|
summary: Rails sharding magic
|
322
322
|
test_files: []
|