switchman 3.3.6 → 3.3.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0e25e9a338b74ed4340f605d27978bba42bd45ef47ddac2bf7c44047db8a014
4
- data.tar.gz: a6f6cdb8f1686213391d38f1eb172fefa9346012f3ce055b152696f1dcd05975
3
+ metadata.gz: 07ef0eeff511916fa7913f453f2b3cde7d5317dfee9e03b58cf3645b2830c845
4
+ data.tar.gz: 2c2c12374387e6856674f14cf965087a0d27c1ccdacc6470b69aec0eb77af22f
5
5
  SHA512:
6
- metadata.gz: fe38ed259e6d881d9f60ecd0dd96b65a3dd154b750beb3b5ee5b8af03e7683f056238feb464fc32c5156841b439200c6ff0c9bf5959dc108b5bb91c298bd450a
7
- data.tar.gz: b74decf8b11511749f80ffc792b2a98dbf6cdf36670d1f2db84a80975138aee8f0f4c11dab8883b9be93413324fb7f574589d6788781cd8e664dea34fe964cbd
6
+ metadata.gz: d62c36fe017fbf801312eb13295e19fbb66c5e9b2aa23996400c3654acca130525580728602328377f4b601d5a9ba09847ef6082948f29af7d1217d7471ffa70
7
+ data.tar.gz: b6afb2bd1e0f69d93dd7b1e7a739cd7a1b6896eee43be063f8452d102de21991f8ab49da3fecc65859e24d66dd54e19f49c6352e22a50dcbd1add00518f154c0
@@ -251,7 +251,7 @@ module Switchman
251
251
 
252
252
  def local_attribute(attr_name)
253
253
  if self.class.sharded_column?(attr_name)
254
- ::Switchman::Shard.local_id_for(attribute(attr_name), shard).first
254
+ ::Switchman::Shard.local_id_for(attribute(attr_name)).first
255
255
  else
256
256
  attribute(attr_name)
257
257
  end
@@ -44,6 +44,23 @@ module Switchman
44
44
  end
45
45
 
46
46
  module MigrationContext
47
+ def migrate(...)
48
+ connection = ::ActiveRecord::Base.connection
49
+ connection_pool = ::ActiveRecord::Base.connection_pool
50
+ previous_schema_cache = connection_pool.get_schema_cache(connection)
51
+ temporary_schema_cache = ::ActiveRecord::ConnectionAdapters::SchemaCache.new(connection)
52
+
53
+ reset_column_information
54
+ connection_pool.set_schema_cache(temporary_schema_cache)
55
+
56
+ begin
57
+ super(...)
58
+ ensure
59
+ connection_pool.set_schema_cache(previous_schema_cache)
60
+ reset_column_information
61
+ end
62
+ end
63
+
47
64
  def migrations
48
65
  return @migrations if instance_variable_defined?(:@migrations)
49
66
 
@@ -51,6 +68,12 @@ module Switchman
51
68
  key = Digest::MD5.hexdigest(migration_files.sort.join(','))
52
69
  @migrations = migrations_cache[key] ||= super
53
70
  end
71
+
72
+ private
73
+
74
+ def reset_column_information
75
+ ::ActiveRecord::Base.descendants.reject { |m| m <= UnshardedRecord }.each(&:reset_column_information)
76
+ end
54
77
  end
55
78
  end
56
79
  end
@@ -221,10 +221,8 @@ module Switchman
221
221
 
222
222
  unless schema == false
223
223
  shard.activate do
224
- with_empty_caches do
225
- ::ActiveRecord::Base.connection.transaction(requires_new: true) do
226
- ::ActiveRecord::Base.connection.migration_context.migrate
227
- end
224
+ ::ActiveRecord::Base.connection.transaction(requires_new: true) do
225
+ ::ActiveRecord::Base.connection.migration_context.migrate
228
226
  end
229
227
 
230
228
  ::ActiveRecord::Base.descendants.reject do |m|
@@ -240,7 +238,6 @@ module Switchman
240
238
  rescue
241
239
  shard&.destroy
242
240
  shard&.drop_database rescue nil unless schema_already_existed
243
- reset_column_information unless schema == false rescue nil
244
241
  raise
245
242
  ensure
246
243
  self.class.creating_new_shard = false
@@ -272,26 +269,5 @@ module Switchman
272
269
  end
273
270
  @primary_shard
274
271
  end
275
-
276
- private
277
-
278
- def reset_column_information
279
- ::ActiveRecord::Base.descendants.reject { |m| m <= UnshardedRecord }.each(&:reset_column_information)
280
- end
281
-
282
- def with_empty_caches
283
- connection = ::ActiveRecord::Base.connection
284
- connection_pool = ::ActiveRecord::Base.connection_pool
285
- previous_schema_cache = connection_pool.get_schema_cache(connection)
286
- temporary_schema_cache = ::ActiveRecord::ConnectionAdapters::SchemaCache.new(connection)
287
-
288
- reset_column_information
289
- connection_pool.set_schema_cache(temporary_schema_cache)
290
-
291
- yield
292
-
293
- connection_pool.set_schema_cache(previous_schema_cache)
294
- reset_column_information
295
- end
296
272
  end
297
273
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Switchman
4
- VERSION = '3.3.6'
4
+ VERSION = '3.3.7'
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.3.6
4
+ version: 3.3.7
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-21 00:00:00.000000000 Z
13
+ date: 2023-03-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord