switchman 3.5.2 → 3.5.3

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: f6fdd3a18ba6864a5a47f6b151f397fb244ac7357c5474fe7195eba633a74a59
4
+ data.tar.gz: 93f9d372028f3807e5396a8d9a75e6f6b267f18d6aa8d46588e471609ce5ac9f
5
5
  SHA512:
6
- metadata.gz: 85626eedd9e74291cbad627523936750dc5a3551bc9cd77e6dd5c49790edeb2e392d974f394bc1f94205b82447be2d4b71c8a108ab63f77947021b6402a64327
7
- data.tar.gz: e288052614bb7e4a872a5aba886829b0b86f1f9105914cfc947badd6ae3323da7e2cbac835521321a71200cd612d2e945ce474546cb87b71205a240e910d1af6
6
+ metadata.gz: 05c39ae962b7585a60e1f896702fbdc0a600c183d4a2c31173d74d710b9616ecb7cedb2ad36b1b65c62a4ee7d6eb0438eb50d482d8fa05a8d6d06469bc9e0643
7
+ data.tar.gz: '020828a35e723d21186d51acdf60c507fb3a1622bc94a43c560cdbd3945a026d6510c395d5308afb42f2029e95972799b67891d11ed5e60ae88b790a84011b6c'
@@ -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
@@ -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.3"
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.3
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-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord