switchman 3.3.5 → 3.3.7

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: b02846fe7319e31d24a50618d5b2f7120109e09c4a4dc40125a25f7299207bf0
4
- data.tar.gz: bd42f42242e7f0b8cc88ca76206625607ad00e33d58247ac6bd9d090f7c3722a
3
+ metadata.gz: 07ef0eeff511916fa7913f453f2b3cde7d5317dfee9e03b58cf3645b2830c845
4
+ data.tar.gz: 2c2c12374387e6856674f14cf965087a0d27c1ccdacc6470b69aec0eb77af22f
5
5
  SHA512:
6
- metadata.gz: 4109620cb05413f9ebfc56290e74e73d94682439a62cd1813b93ffb2b28aff2ec84aafb5bb888a283e418c8fcbe743b384bc09d3cd18f2d5008920e2707d491f
7
- data.tar.gz: c5ce42651aed4080935281b4a131d56517bf84dc78c2dc38f0ce3ec6db62387b0848120392eb2187e8f86a2b61557c0a1ad34e1482cbed2f9b3f4cfbf90bfd22
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,12 +221,10 @@ module Switchman
221
221
 
222
222
  unless schema == false
223
223
  shard.activate do
224
- reset_column_information
225
-
226
224
  ::ActiveRecord::Base.connection.transaction(requires_new: true) do
227
225
  ::ActiveRecord::Base.connection.migration_context.migrate
228
226
  end
229
- reset_column_information
227
+
230
228
  ::ActiveRecord::Base.descendants.reject do |m|
231
229
  m <= UnshardedRecord || !m.table_exists?
232
230
  end.each(&:define_attribute_methods)
@@ -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,11 +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
272
  end
282
273
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Switchman
4
- VERSION = '3.3.5'
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.5
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