database_consistency 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/database_consistency/checkers/enum_checkers/enum_type_checker.rb +5 -6
- data/lib/database_consistency/checkers/validators_fraction_checkers/column_presence_checker.rb +3 -18
- data/lib/database_consistency/version.rb +1 -1
- data/lib/database_consistency/writers/autofix/migration_base.rb +3 -1
- data/lib/database_consistency/writers/simple/base.rb +3 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c6d7fe7d9a50ab2233cca7b018d096f9d47b850e2fb92b2724fecba15eb78e6
|
4
|
+
data.tar.gz: 5c98abb3adb05dfddb3c586e3eae4a87d35069d07332c516154791514cc9c70f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32ee0e823c4c893f5e062f847f33dca5fe6094bfc98d12786f879cbe6a2d2182a44f5d9756271550b524093c56030d38f72ce4ff58de6175b2936852e3e7d3d0
|
7
|
+
data.tar.gz: 210a2a55056fee4992ad8e7b719aa42604b03944891e2061976b27972ad8fd5c7b8ac920fb5b888f193a0dd2fbb27e2a205ffba1252a83c736a5926a471641db
|
@@ -4,8 +4,6 @@ module DatabaseConsistency
|
|
4
4
|
module Checkers
|
5
5
|
# This class checks enum types consistency
|
6
6
|
class EnumTypeChecker < EnumChecker
|
7
|
-
MissingColumn = Class.new(StandardError)
|
8
|
-
|
9
7
|
Report = DatabaseConsistency::ReportBuilder.define(
|
10
8
|
DatabaseConsistency::Report,
|
11
9
|
:column_type,
|
@@ -15,7 +13,7 @@ module DatabaseConsistency
|
|
15
13
|
private
|
16
14
|
|
17
15
|
def preconditions
|
18
|
-
|
16
|
+
column.present?
|
19
17
|
end
|
20
18
|
|
21
19
|
def check
|
@@ -53,10 +51,11 @@ module DatabaseConsistency
|
|
53
51
|
model.defined_enums[enum].values.map(&:class).uniq
|
54
52
|
end
|
55
53
|
|
56
|
-
def
|
57
|
-
column
|
58
|
-
|
54
|
+
def column
|
55
|
+
@column ||= model.columns.find { |c| c.name.to_s == enum.to_s }
|
56
|
+
end
|
59
57
|
|
58
|
+
def column_type
|
60
59
|
column.type.to_s
|
61
60
|
end
|
62
61
|
|
data/lib/database_consistency/checkers/validators_fraction_checkers/column_presence_checker.rb
CHANGED
@@ -20,26 +20,13 @@ module DatabaseConsistency
|
|
20
20
|
|
21
21
|
# We skip the check when there are no presence validators
|
22
22
|
def preconditions
|
23
|
-
validators.any? && !association?
|
23
|
+
column && validators.any? && !association?
|
24
24
|
end
|
25
25
|
|
26
26
|
def association?
|
27
27
|
model._reflect_on_association(attribute)&.macro == :has_one
|
28
28
|
end
|
29
29
|
|
30
|
-
# Table of possible statuses
|
31
|
-
# | allow_nil/allow_blank/if/unless | database | status |
|
32
|
-
# | ------------------------------- | -------- | ------ |
|
33
|
-
# | at least one provided | required | fail |
|
34
|
-
# | at least one provided | optional | ok |
|
35
|
-
# | all missing | required | ok |
|
36
|
-
# | all missing | optional | fail |
|
37
|
-
def check
|
38
|
-
report_message
|
39
|
-
rescue Errors::MissingField => e
|
40
|
-
report_template(:fail, error_message: e.message)
|
41
|
-
end
|
42
|
-
|
43
30
|
def report_template(status, error_message: nil, error_slug: nil)
|
44
31
|
Report.new(
|
45
32
|
status: status,
|
@@ -55,7 +42,7 @@ module DatabaseConsistency
|
|
55
42
|
validators.all? { |validator| validator.options.slice(*WEAK_OPTIONS).any? }
|
56
43
|
end
|
57
44
|
|
58
|
-
def
|
45
|
+
def check # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
59
46
|
can_be_null = column.null
|
60
47
|
has_weak_option = weak_option?
|
61
48
|
|
@@ -84,9 +71,7 @@ module DatabaseConsistency
|
|
84
71
|
end
|
85
72
|
|
86
73
|
def column
|
87
|
-
@column ||= regular_column ||
|
88
|
-
association_reference_column ||
|
89
|
-
(raise Errors::MissingField, "column (#{attribute}) is missing in table (#{model.table_name}) but used for presence validation") # rubocop:disable Layout/LineLength
|
74
|
+
@column ||= (regular_column || association_reference_column)
|
90
75
|
end
|
91
76
|
|
92
77
|
def regular_column
|
@@ -17,7 +17,9 @@ module DatabaseConsistency
|
|
17
17
|
private
|
18
18
|
|
19
19
|
def migration
|
20
|
-
File.read(template_path)
|
20
|
+
attributes.merge(migration_configuration(migration_name)).reduce(File.read(template_path)) do |str, (k, v)|
|
21
|
+
str.gsub("%<#{k}>s", v.to_s)
|
22
|
+
end
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|