switchman 3.5.2 → 3.5.3
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 +4 -4
- data/lib/switchman/active_record/calculations.rb +17 -4
- data/lib/switchman/shard.rb +26 -35
- data/lib/switchman/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6fdd3a18ba6864a5a47f6b151f397fb244ac7357c5474fe7195eba633a74a59
|
4
|
+
data.tar.gz: 93f9d372028f3807e5396a8d9a75e6f6b267f18d6aa8d46588e471609ce5ac9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
146
|
-
|
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
|
data/lib/switchman/shard.rb
CHANGED
@@ -541,48 +541,39 @@ module Switchman
|
|
541
541
|
end
|
542
542
|
|
543
543
|
def drop_database
|
544
|
-
raise
|
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
|
-
|
549
|
-
|
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
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
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
|
|
data/lib/switchman/version.rb
CHANGED
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.
|
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-
|
13
|
+
date: 2023-06-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|