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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 35156353c0e52e42bbd52b37cf2733d7c0acb6736e676ddac31156ce2b133335
4
- data.tar.gz: 6406ba00901ecc5c17271e0b30d77c4ccf739db9cd589e153dae77102cb036fd
3
+ metadata.gz: eb62453808b659106e48a2279bdabeb2901c97187eaf8ae6cd612d460096f6d0
4
+ data.tar.gz: 5cf42b899e7a63f73bf5604247a8e2b2cd4a998bd7f4f0986180e451e66d3cc0
5
5
  SHA512:
6
- metadata.gz: cd9e7047f1a19dbde96372f944441ea181952480050218fa24b12d7a5aea4fef4a153a2fa44c5e3eae601ac308ab4c312a3e1bbfffe92e68bbffafc5d31c4051
7
- data.tar.gz: e6a34fe7f23e07865eccb6aab6722f07f97b12e561057406c55e0c7d905c9eea85be50fd197c679f9ab3c8a72c28644d4e96eb6d2c5c8eab8ad8ac42de895840
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: just return MIGRATOR_SALT directly
24
- # especially if you're going through pgbouncer, the database
25
- # name you're accessing may not be consistent. it is NOT allowed
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
- ::ActiveRecord::Migrator::MIGRATOR_SALT
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Switchman
4
- VERSION = '3.1.1'
4
+ VERSION = '3.1.2'
5
5
  end
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.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-06-02 00:00:00.000000000 Z
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: []