switchman 3.6.7 → 4.0.0

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: 2e86d08703a350aa5b8d3d843c51a0813f00e6ee0c681d0c95094f84863b327b
4
- data.tar.gz: f13e438d68d996f55c9be543cc8cb89967b62f9ddd111ab4fae188da8b959096
3
+ metadata.gz: eb5bc75d858d97e55442dfdafcd1826d7040fe1bd4819bc3c2ee6053257a72ab
4
+ data.tar.gz: e73beaf3a5987f26e2402078f66c028831afc6924f21546d0ca1cb35f70e0831
5
5
  SHA512:
6
- metadata.gz: 7be63615d79be0b46184b9e6754bcb6091873e2eb0c4722705daea7dd81dd50320819b2238538c818637901570c2ad47a7ed62febd441c4d5b130c78391554cc
7
- data.tar.gz: c3eb6290f9437ccac7162216840c2f258f31fc6c978121b9054c6308640bff6d522f2f61fd2247fea178c1c173a012a4d7f2c22b2e234d7b4f431ce4b8306403
6
+ metadata.gz: 273718d8bc773ded149ac5d81509a6d85c6858f17bc7c1a03f3dbdf15bbb96f101fea5842eddf87ba442aabf1f0bffe1a21421da4b9329548b0f40e51de26645
7
+ data.tar.gz: 9f81d1963fe213d334aed7377057fe29ecbdb637c6b2b8a33a49d52fcc0f726e1a8e87853a6e1030c8c2b0bbaff51e369d54cf8118f1c512ca0d62bf5684267c
@@ -203,41 +203,7 @@ module Switchman
203
203
  # #compare_by_identity makes such owners different hash keys
204
204
  @records_by_owner = {}.compare_by_identity
205
205
 
206
- if ::Rails.version >= "7.0"
207
- raw_records ||= loader_query.records_for([self])
208
- elsif owner_keys.empty?
209
- raw_records ||= []
210
- else
211
- # determine the shard to search for each owner
212
- if reflection.macro == :belongs_to
213
- # for belongs_to, it's the shard of the foreign_key
214
- partition_proc = lambda do |owner|
215
- if owner.class.sharded_column?(owner_key_name)
216
- Shard.shard_for(owner[owner_key_name], owner.shard)
217
- else
218
- Shard.current
219
- end
220
- end
221
- elsif !reflection.options[:multishard]
222
- # for non-multishard associations, it's *just* the owner's shard
223
- partition_proc = ->(owner) { owner.shard }
224
- end
225
-
226
- raw_records ||= Shard.partition_by_shard(owners, partition_proc) do |partitioned_owners|
227
- relative_owner_keys = partitioned_owners.map do |owner|
228
- key = owner[owner_key_name]
229
- if key && owner.class.sharded_column?(owner_key_name)
230
- key = Shard.relative_id_for(key,
231
- owner.shard,
232
- Shard.current(klass.connection_class_for_self))
233
- end
234
- convert_key(key)
235
- end
236
- relative_owner_keys.compact!
237
- relative_owner_keys.uniq!
238
- records_for(relative_owner_keys)
239
- end
240
- end
206
+ raw_records ||= loader_query.records_for([self])
241
207
 
242
208
  @preloaded_records = raw_records.select do |record|
243
209
  assignments = false
@@ -55,12 +55,7 @@ module Switchman
55
55
  end
56
56
 
57
57
  def define_cached_method(owner, name, namespace:, as:, &block)
58
- if ::Rails.version < "7.0"
59
- yield owner
60
- owner.rename_method(as, name)
61
- else
62
- owner.define_cached_method(name, namespace: namespace, as: as, &block)
63
- end
58
+ owner.define_cached_method(name, namespace: namespace, as: as, &block)
64
59
  end
65
60
 
66
61
  def define_method_global_attribute(attr_name, owner:)
@@ -136,11 +136,7 @@ module Switchman
136
136
  end
137
137
 
138
138
  def connected_to_stack
139
- has_own_stack = if ::Rails.version < "7.0"
140
- Thread.current.thread_variable?(:ar_connected_to_stack)
141
- else
142
- ::ActiveSupport::IsolatedExecutionState.key?(:active_record_connected_to_stack)
143
- end
139
+ has_own_stack = ::ActiveSupport::IsolatedExecutionState.key?(:active_record_connected_to_stack)
144
140
 
145
141
  ret = super
146
142
  return ret if has_own_stack
@@ -189,12 +185,6 @@ module Switchman
189
185
 
190
186
  Shard.default
191
187
  end
192
-
193
- if ::Rails.version < "7.0"
194
- def connection_class_for_self
195
- connection_classes
196
- end
197
- end
198
188
  end
199
189
 
200
190
  def self.prepended(klass)
@@ -148,19 +148,10 @@ module Switchman
148
148
  private
149
149
 
150
150
  def type_cast_calculated_value_switchman(value, column_name, operation)
151
- if ::Rails.version < "7.0"
152
- type_cast_calculated_value(value, operation) do |val|
153
- column = aggregate_column(column_name)
154
- type ||= column.try(:type_caster) ||
155
- lookup_cast_type_from_join_dependencies(column_name.to_s) || ::ActiveRecord::Type.default_value
156
- type.deserialize(val)
157
- end
158
- else
159
- column = aggregate_column(column_name)
160
- type ||= column.try(:type_caster) ||
161
- lookup_cast_type_from_join_dependencies(column_name.to_s) || ::ActiveRecord::Type.default_value
162
- type_cast_calculated_value(value, operation, type)
163
- end
151
+ column = aggregate_column(column_name)
152
+ type ||= column.try(:type_caster) ||
153
+ lookup_cast_type_from_join_dependencies(column_name.to_s) || ::ActiveRecord::Type.default_value
154
+ type_cast_calculated_value(value, operation, type)
164
155
  end
165
156
 
166
157
  def column_name_for(field)
@@ -60,7 +60,7 @@ module Switchman
60
60
  private
61
61
 
62
62
  def current_shard
63
- (::Rails.version < "7.0") ? connection_klass.current_switchman_shard : connection_class.current_switchman_shard
63
+ connection_class.current_switchman_shard
64
64
  end
65
65
 
66
66
  def tls_key
@@ -55,7 +55,7 @@ module Switchman
55
55
  end
56
56
 
57
57
  def load(&block)
58
- if !loaded? || (::Rails.version >= "7.0" && scheduled?)
58
+ if !loaded? || scheduled?
59
59
  @records = activate { |relation| relation.send(:exec_queries, &block) }
60
60
  @loaded = true
61
61
  end
@@ -10,20 +10,9 @@ module Switchman
10
10
 
11
11
  ::GuardRail.singleton_class.prepend(GuardRail::ClassMethods)
12
12
 
13
- # after :initialize_dependency_mechanism to ensure autoloading is
14
- # configured for any downstream initializers that care. In rails 7.0 we
15
- # should be able to just use an explicit after on configuring the once
16
- # autoloaders and not need to go monkey around with initializer order
17
- if ::Rails.version < "7.0"
18
- initialize_dependency_mechanism = ::Rails::Application::Bootstrap.initializers.find do |i|
19
- i.name == :initialize_dependency_mechanism
20
- end
21
- initialize_dependency_mechanism.instance_variable_get(:@options)[:after] = :set_autoload_paths
22
- end
23
-
24
13
  initializer "switchman.active_record_patch",
25
14
  before: "active_record.initialize_database",
26
- after: ((::Rails.version < "7.0") ? :initialize_dependency_mechanism : :setup_once_autoloader) do
15
+ after: :setup_once_autoloader do
27
16
  ::ActiveSupport.on_load(:active_record) do
28
17
  # Switchman requires postgres, so just always load the pg adapter
29
18
  require "active_record/connection_adapters/postgresql_adapter"
@@ -54,11 +43,9 @@ module Switchman
54
43
  ::ActiveRecord::Associations::CollectionProxy.include(ActiveRecord::Associations::CollectionProxy)
55
44
 
56
45
  ::ActiveRecord::Associations::Preloader::Association.prepend(ActiveRecord::Associations::Preloader::Association)
57
- unless ::Rails.version < "7.0"
58
- ::ActiveRecord::Associations::Preloader::Association::LoaderRecords.prepend(
59
- ActiveRecord::Associations::Preloader::Association::LoaderRecords
60
- )
61
- end
46
+ ::ActiveRecord::Associations::Preloader::Association::LoaderRecords.prepend(
47
+ ActiveRecord::Associations::Preloader::Association::LoaderRecords
48
+ )
62
49
  ::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(ActiveRecord::AbstractAdapter)
63
50
  unless ::Rails.version < "7.1"
64
51
  ::ActiveRecord::ConnectionAdapters::ConnectionHandler.prepend(ActiveRecord::ConnectionHandler)
@@ -126,6 +126,7 @@ module Switchman
126
126
  ds.shards.delete_all unless use_transactional_tests
127
127
  ds.destroy
128
128
  end
129
+ ds.remove_instance_variable(:@primary_shard_id) if ds.instance_variable_defined?(:@primary_shard_id)
129
130
  end
130
131
  end
131
132
 
@@ -16,11 +16,7 @@ module Switchman
16
16
  payload[:shard] = {
17
17
  database_server_id: shard.database_server.id,
18
18
  id: shard.id,
19
- env: if ::Rails.version < "7.0"
20
- @shard_host.pool.connection_klass&.current_role
21
- else
22
- @shard_host.pool.connection_class&.current_role
23
- end
19
+ env: @shard_host.pool.connection_class&.current_role
24
20
  }
25
21
  end
26
22
  super(name, payload)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Switchman
4
- VERSION = "3.6.7"
4
+ VERSION = "4.0.0"
5
5
  end
@@ -1,16 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # In rails 7.0+ if you have only 1 db in the env it doesn't try to do explicit activation
4
- # (and for rails purposes we only have one db per env because each database server is a separate env)
5
- if Rails.version < "7.0"
6
- task_prefix = Rake::Task.task_defined?("app:db:migrate") ? "app:db" : "db"
7
- Rake::Task["#{task_prefix}:migrate"].clear_actions.enhance do
8
- ActiveRecord::Tasks::DatabaseTasks.migrate
9
- # Ensure this doesn't blow up when running inside the dummy app
10
- Rake::Task["#{task_prefix}:_dump"].invoke
11
- end
12
- end
13
-
14
3
  module Switchman
15
4
  module Rake
16
5
  def self.filter_database_servers
@@ -265,28 +254,9 @@ module Switchman
265
254
 
266
255
  module ActiveRecord
267
256
  module PostgreSQLDatabaseTasks
268
- if ::Rails.version < "7.0"
269
- def structure_dump(filename, extra_flags = nil)
270
- set_psql_env
271
- args = ["--schema-only", "--no-privileges", "--no-owner", "--file", filename]
272
- args.concat(Array(extra_flags)) if extra_flags
273
- shard = Shard.current.name
274
- serialized_search_path = shard
275
- args << "--schema=#{Shellwords.escape(shard)}"
276
-
277
- ignore_tables = ::ActiveRecord::SchemaDumper.ignore_tables
278
- args += ignore_tables.flat_map { |table| ["-T", table] } if ignore_tables.any?
279
-
280
- args << db_config.database
281
- run_cmd("pg_dump", args, "dumping")
282
- remove_sql_header_comments(filename)
283
- File.open(filename, "a") { |f| f << "SET search_path TO #{serialized_search_path};\n\n" }
284
- end
285
- else
286
- def structure_dump(...)
287
- ::ActiveRecord.dump_schemas = Switchman::Shard.current.name
288
- super
289
- end
257
+ def structure_dump(...)
258
+ ::ActiveRecord.dump_schemas = Switchman::Shard.current.name
259
+ super
290
260
  end
291
261
  end
292
262
  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.6.7
4
+ version: 4.0.0
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: 2024-09-11 00:00:00.000000000 Z
13
+ date: 2025-02-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: 6.1.4
21
+ version: '7.0'
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
24
  version: '7.2'
@@ -28,7 +28,7 @@ dependencies:
28
28
  requirements:
29
29
  - - ">="
30
30
  - !ruby/object:Gem::Version
31
- version: 6.1.4
31
+ version: '7.0'
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
34
  version: '7.2'
@@ -66,7 +66,7 @@ dependencies:
66
66
  requirements:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: '6.1'
69
+ version: '7.0'
70
70
  - - "<"
71
71
  - !ruby/object:Gem::Version
72
72
  version: '7.2'
@@ -76,7 +76,7 @@ dependencies:
76
76
  requirements:
77
77
  - - ">="
78
78
  - !ruby/object:Gem::Version
79
- version: '6.1'
79
+ version: '7.0'
80
80
  - - "<"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '7.2'