switchman 3.4.0 → 3.4.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: be3660461c9c52c63b304de0bb3e5a18e3fe3cdfe7d5f61802b2db2b232f97be
4
- data.tar.gz: 47248f2cb8c6c35396d537e7bd1f938399811d11eb1a07a96778654ccf5dc3f9
3
+ metadata.gz: 28d87755bf2331cbbf2931e7d35dddd688983c168c583b27dd60ae58d78072db
4
+ data.tar.gz: 500e141f914db02c5dd51cd9a595abc00306750a418641ceb09adb7cee207de7
5
5
  SHA512:
6
- metadata.gz: 60d5b3eb13458b61bbdc8d2a729e10f870284d35fa0694612d793ed8ff9fd15667777dda2e4d28e4fb435a707aff0ca483e51032b396d7496b5d3792e6d6be16
7
- data.tar.gz: fa52c0f4ddf8fea8602917d64f165602ee14ffb9ea72f609a7f9d11e2ac511b5ba3cae9a8ae9915791c268adc0c9f9ef12f142817d0e472bf1c3a17b1f3e262c
6
+ metadata.gz: 94c9b870a65599c0d5775d32cd9dd1bfc3235c541eeb07127e5e8e8c773447da3ba1e0460ce8a340709354aceede546b9d6ccf8dd0360bff7e494f267a6791e1
7
+ data.tar.gz: 6ea8348a8aaa9eb80ae763d2c8ccca23949e329f0f9ae2df7eef59344fdf3d4660b6e7419f479bc5d67be5e42fdd73f49abf7f0ceb853c0469c38b0899559424
@@ -171,11 +171,22 @@ module Switchman
171
171
  end
172
172
  end
173
173
 
174
+ def destroy_shadow_records(target_shards: [Shard.current])
175
+ raise Errors::ShadowRecordError, 'Cannot be called on a shadow record.' if shadow_record?
176
+ raise Errors::MethodUnsupportedForUnshardedTableError, 'Cannot be called on a record belonging to an unsharded table.' unless self.class.sharded_column?(self.class.primary_key)
177
+
178
+ Array(target_shards).each do |target_shard|
179
+ next if target_shard == shard
180
+
181
+ target_shard.activate { self.class.where('id = ?', global_id).delete_all }
182
+ end
183
+ end
184
+
174
185
  # Returns "the shard that this record was actually loaded from" , as
175
186
  # opposed to "the shard this record belongs on", which might be
176
187
  # different if this is a shadow record.
177
188
  def loaded_from_shard
178
- @loaded_from_shard || fallback_shard
189
+ @loaded_from_shard || shard
179
190
  end
180
191
 
181
192
  def shard
@@ -2,14 +2,18 @@
2
2
 
3
3
  module Switchman
4
4
  module Errors
5
- class NonExistentShardError < RuntimeError; end
6
-
7
- class ParallelShardExecError < RuntimeError; end
8
-
9
5
  class ManuallyCreatedShadowRecordError < RuntimeError
10
6
  def initialize(msg = "It looks like you're trying to manually create a shadow record. Please use Switchman::ActiveRecord::Base#save_shadow_record instead.")
11
7
  super
12
8
  end
13
9
  end
10
+
11
+ class NonExistentShardError < RuntimeError; end
12
+
13
+ class ParallelShardExecError < RuntimeError; end
14
+
15
+ class ShadowRecordError < RuntimeError; end
16
+
17
+ class UnshardedTableError < RuntimeError; end
14
18
  end
15
19
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Switchman
4
- VERSION = '3.4.0'
4
+ VERSION = '3.4.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switchman
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 3.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-03-31 00:00:00.000000000 Z
13
+ date: 2023-04-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord