activerecord-overflow_signalizer 1.1.0 → 2.0.0
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c758da52b5a1ca2e01acaca51575575e1a5f9b0b
|
4
|
+
data.tar.gz: 46e307fb0fb06eef155e0820d83a1874a536454a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89a1ba0120a8f88953ed9037cb6344f7d3153aa0200f486123d318549d0d721514b320f0c68d98544bee77ba388898174bc03038e44927baf3092ae8fd472b6a
|
7
|
+
data.tar.gz: a737bdde1217643433e357980be3942bed85898b5665d0ef32983cb23835a7947970fe6f2b8248597c5eccc7fb8ba35270fad059f18946b77d4ed668d8b01704
|
@@ -22,17 +22,19 @@ module ActiveRecord
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def analyse!
|
25
|
+
overflowed_tables = []
|
25
26
|
@models.group_by(&:table_name).each do |table, models|
|
26
27
|
model = models.first
|
27
28
|
next if model.abstract_class? || model.last.nil?
|
28
29
|
pk = model.columns.select { |c| c.name == model.primary_key }.first
|
29
30
|
max = MAX_VALUE.fetch(pk.sql_type) do |type|
|
30
|
-
|
31
|
+
@logger.warn "Model #{model} has primary_key #{model.primary_key} with unsupported type #{type}"
|
31
32
|
end
|
32
33
|
if overflow_soon?(max, model)
|
33
|
-
|
34
|
+
overflowed_tables << [table, model.last.public_send(pk.name), max]
|
34
35
|
end
|
35
36
|
end
|
37
|
+
raise Overflow, overflow_message(overflowed_tables) if overflowed_tables.any?
|
36
38
|
end
|
37
39
|
|
38
40
|
def analyse
|
@@ -61,12 +63,17 @@ module ActiveRecord
|
|
61
63
|
week_records.reduce(:+) / week_records.keep_if { |v| v > 0 }.size
|
62
64
|
end
|
63
65
|
|
64
|
-
def overflow_message(
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
66
|
+
def overflow_message(overflowed_tables)
|
67
|
+
overflowed = []
|
68
|
+
overflow_soon = []
|
69
|
+
overflowed_tables.each do |table, current_value, max_value|
|
70
|
+
if current_value == max_value
|
71
|
+
overflowed << table
|
72
|
+
else
|
73
|
+
overflow_soon << table
|
74
|
+
end
|
69
75
|
end
|
76
|
+
"Owerflowed tables: #{overflowed}. Overflow soon tables: #{overflow_soon}"
|
70
77
|
end
|
71
78
|
|
72
79
|
def signalize(msg)
|