switchman 3.5.2 → 3.5.4

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: 9a91e85cce6bc5ae253213341573bb4937692ce0763bb4359ffa5ee4b12d8a2e
4
- data.tar.gz: deae9f167202394f6a8d02910a911f4d64a2d944ed9406f0263861b8f609ca82
3
+ metadata.gz: 524551c3432d001d8cbfc030baa81bf534d75b4fd9ac8a5224a018bd31ef40d8
4
+ data.tar.gz: 0dbb04287be903ca4ec0c08df57fbc2f7913795baf3ae14cde806eb0c145b3a7
5
5
  SHA512:
6
- metadata.gz: 85626eedd9e74291cbad627523936750dc5a3551bc9cd77e6dd5c49790edeb2e392d974f394bc1f94205b82447be2d4b71c8a108ab63f77947021b6402a64327
7
- data.tar.gz: e288052614bb7e4a872a5aba886829b0b86f1f9105914cfc947badd6ae3323da7e2cbac835521321a71200cd612d2e945ce474546cb87b71205a240e910d1af6
6
+ metadata.gz: 9fc1195f6ae2b2d5c8041610c3bd2bd814a25db507ead5263a5bbe42331d852d21f2b8b9bb143ea8ee78f0d16303386e3f42a2acda8aabbdd862efab3fe17e7e
7
+ data.tar.gz: c2a6ca3e3347342474a04e882c2b10635219404427b80b3c89d1d7a26686cc15355a8c3fcf60972ce2a8ed44a7fcdb020958c7611046653d5f53e47f087d85ca
@@ -131,7 +131,12 @@ module Switchman
131
131
  def grouped_calculation_options(operation, column_name, distinct)
132
132
  opts = { operation: operation, column_name: column_name, distinct: distinct }
133
133
 
134
- opts[:aggregate_alias] = aggregate_alias_for(operation, column_name)
134
+ # Rails 7.0.5
135
+ if defined?(::ActiveRecord::Calculations::ColumnAliasTracker)
136
+ column_alias_tracker = ::ActiveRecord::Calculations::ColumnAliasTracker.new(connection)
137
+ end
138
+
139
+ opts[:aggregate_alias] = aggregate_alias_for(operation, column_name, column_alias_tracker)
135
140
  group_attrs = group_values
136
141
  if group_attrs.first.respond_to?(:to_sym)
137
142
  association = klass.reflect_on_association(group_attrs.first.to_sym)
@@ -142,8 +147,14 @@ module Switchman
142
147
  group_fields = group_attrs
143
148
  end
144
149
 
145
- # to_s is because Rails 5 returns a string but Rails 6 returns a symbol.
146
- group_aliases = group_fields.map { |field| column_alias_for(field.downcase.to_s).to_s }
150
+ group_aliases = group_fields.map do |field|
151
+ field = connection.visitor.compile(field) if ::Arel.arel_node?(field)
152
+ if column_alias_tracker
153
+ column_alias_tracker.alias_for(field.to_s.downcase)
154
+ else
155
+ column_alias_for(field.to_s.downcase)
156
+ end
157
+ end
147
158
  group_columns = group_aliases.zip(group_fields).map do |aliaz, field|
148
159
  [aliaz, type_for(field), column_name_for(field)]
149
160
  end
@@ -156,11 +167,13 @@ module Switchman
156
167
  opts
157
168
  end
158
169
 
159
- def aggregate_alias_for(operation, column_name)
170
+ def aggregate_alias_for(operation, column_name, column_alias_tracker)
160
171
  if operation == "count" && column_name == :all
161
172
  "count_all"
162
173
  elsif operation == "average"
163
174
  "average"
175
+ elsif column_alias_tracker
176
+ column_alias_tracker.alias_for("#{operation} #{column_name}")
164
177
  else
165
178
  column_alias_for("#{operation} #{column_name}")
166
179
  end
@@ -10,6 +10,11 @@ module Switchman
10
10
  Switchman.cache.delete("default_shard")
11
11
  Shard.default(reload: true)
12
12
  end
13
+
14
+ def raise_for_multi_db(*)
15
+ # ignore; Switchman doesn't use namespaced tasks for multiple shards; it uses
16
+ # environment variables to filter which shards you want to target
17
+ end
13
18
  end
14
19
  end
15
20
  end
@@ -541,48 +541,39 @@ module Switchman
541
541
  end
542
542
 
543
543
  def drop_database
544
- raise("Cannot drop the database of the default shard") if default?
544
+ raise "Cannot drop the database of the default shard" if default?
545
545
  return unless read_attribute(:name)
546
546
 
547
547
  begin
548
- adapter = database_server.config[:adapter]
549
- sharding_config = Switchman.config || {}
550
- drop_statement = sharding_config[adapter]&.[](:drop_statement)
551
- drop_statement ||= sharding_config[:drop_statement]
552
- if drop_statement
553
- drop_statement = Array(drop_statement).dup
554
- .map { |statement| statement.gsub("%{name}", name) }
548
+ activate do
549
+ self.class.drop_database(name)
555
550
  end
551
+ rescue ::ActiveRecord::StatementInvalid => e
552
+ logger.error "Drop failed: #{e}"
553
+ end
554
+ end
556
555
 
557
- case adapter
558
- when "mysql", "mysql2"
559
- activate do
560
- ::GuardRail.activate(:deploy) do
561
- drop_statement ||= "DROP DATABASE #{name}"
562
- Array(drop_statement).each do |stmt|
563
- ::ActiveRecord::Base.connection.execute(stmt)
564
- end
565
- end
566
- end
567
- when "postgresql"
568
- activate do
569
- ::GuardRail.activate(:deploy) do
570
- # Shut up, Postgres!
571
- conn = ::ActiveRecord::Base.connection
572
- old_proc = conn.raw_connection.set_notice_processor {}
573
- begin
574
- drop_statement ||= "DROP SCHEMA #{name} CASCADE"
575
- Array(drop_statement).each do |stmt|
576
- ::ActiveRecord::Base.connection.execute(stmt)
577
- end
578
- ensure
579
- conn.raw_connection.set_notice_processor(&old_proc) if old_proc
580
- end
581
- end
556
+ #
557
+ # Drops a specific database/schema from the currently active connection
558
+ #
559
+ def self.drop_database(name)
560
+ sharding_config = Switchman.config || {}
561
+ drop_statement = sharding_config["postgresql"]&.[](:drop_statement)
562
+ drop_statement ||= sharding_config[:drop_statement]
563
+ drop_statement = Array(drop_statement).map { |statement| statement.gsub("%{name}", name) } if drop_statement
564
+
565
+ ::GuardRail.activate(:deploy) do
566
+ # Shut up, Postgres!
567
+ conn = ::ActiveRecord::Base.connection
568
+ old_proc = conn.raw_connection.set_notice_processor {}
569
+ begin
570
+ drop_statement ||= "DROP SCHEMA #{name} CASCADE"
571
+ Array(drop_statement).each do |stmt|
572
+ ::ActiveRecord::Base.connection.execute(stmt)
582
573
  end
574
+ ensure
575
+ conn.raw_connection.set_notice_processor(&old_proc) if old_proc
583
576
  end
584
- rescue
585
- logger.info "Drop failed: #{$!}"
586
577
  end
587
578
  end
588
579
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Switchman
4
- VERSION = "3.5.2"
4
+ VERSION = "3.5.4"
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.5.2
4
+ version: 3.5.4
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-05-24 00:00:00.000000000 Z
13
+ date: 2023-06-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord