database_consistency 1.7.12 → 1.7.15
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/association_checkers/foreign_key_checker.rb +2 -0
- data/lib/database_consistency/checkers/association_checkers/foreign_key_type_checker.rb +2 -1
- data/lib/database_consistency/checkers/association_checkers/missing_association_class_checker.rb +36 -0
- data/lib/database_consistency/checkers/model_checkers/missing_table_checker.rb +22 -0
- data/lib/database_consistency/checkers/model_checkers/model_checker.rb +23 -0
- data/lib/database_consistency/helper.rb +8 -3
- data/lib/database_consistency/processors/associations_processor.rb +2 -1
- data/lib/database_consistency/processors/base_processor.rb +2 -1
- data/lib/database_consistency/processors/models_processor.rb +26 -0
- data/lib/database_consistency/version.rb +1 -1
- data/lib/database_consistency/writers/simple/base.rb +6 -3
- data/lib/database_consistency/writers/simple/missing_association_class.rb +27 -0
- data/lib/database_consistency/writers/simple/missing_table.rb +21 -0
- data/lib/database_consistency/writers/simple_writer.rb +8 -6
- data/lib/database_consistency.rb +7 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3621ad7d1790987ba3867541950d611af17e26be2da7bbc1a33914db25292872
|
4
|
+
data.tar.gz: 8d26e698a1c2ca1f8ba37e2ca899b3486730a025e7b4377645603eda312c0d59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aedb071d671ca0a4b92a060c58aced55e4e49039d80fbb8d0fc6aa2062070763d5ae4d08333c32cdc3c65fcdb4bf7798875076b47d342c541d1e73ce7c3e57d3
|
7
|
+
data.tar.gz: 82c070e44a36db48e84f17f701168d2fc02f019bd61dcdc9fa43d2cd79039eb865f8466215a75940a66b0cc782417a5adfe47394e4ed1b046164a6e43ce89092
|
@@ -25,7 +25,8 @@ module DatabaseConsistency
|
|
25
25
|
!association.polymorphic? &&
|
26
26
|
association.through_reflection.nil? &&
|
27
27
|
association.klass.present? &&
|
28
|
-
association.macro != :has_and_belongs_to_many
|
28
|
+
association.macro != :has_and_belongs_to_many &&
|
29
|
+
association.klass.table_exists?
|
29
30
|
rescue NameError
|
30
31
|
false
|
31
32
|
end
|
data/lib/database_consistency/checkers/association_checkers/missing_association_class_checker.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
module Checkers
|
5
|
+
# This class checks if an association has existing class defined
|
6
|
+
class MissingAssociationClassChecker < AssociationChecker
|
7
|
+
Report = ReportBuilder.define(
|
8
|
+
DatabaseConsistency::Report,
|
9
|
+
:class_name
|
10
|
+
)
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def preconditions
|
15
|
+
!association.polymorphic?
|
16
|
+
end
|
17
|
+
|
18
|
+
def check
|
19
|
+
association.klass
|
20
|
+
report_template(:ok)
|
21
|
+
rescue NameError
|
22
|
+
report_template(:fail, error_slug: :missing_association_class)
|
23
|
+
end
|
24
|
+
|
25
|
+
def report_template(status, error_slug: nil)
|
26
|
+
Report.new(
|
27
|
+
status: status,
|
28
|
+
error_message: nil,
|
29
|
+
error_slug: error_slug,
|
30
|
+
class_name: association.class_name,
|
31
|
+
**report_attributes
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
module Checkers
|
5
|
+
# This class checks that a model has a corresponding table
|
6
|
+
class MissingTableChecker < ModelChecker
|
7
|
+
private
|
8
|
+
|
9
|
+
def preconditions
|
10
|
+
!model.abstract_class?
|
11
|
+
end
|
12
|
+
|
13
|
+
def check
|
14
|
+
if model.table_exists?
|
15
|
+
report_template(:ok)
|
16
|
+
else
|
17
|
+
report_template(:fail, error_slug: :missing_table)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
module Checkers
|
5
|
+
# The base class for model checkers
|
6
|
+
class ModelChecker < BaseChecker
|
7
|
+
attr_reader :model
|
8
|
+
|
9
|
+
def initialize(model)
|
10
|
+
super()
|
11
|
+
@model = model
|
12
|
+
end
|
13
|
+
|
14
|
+
def column_or_attribute_name
|
15
|
+
nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def table_or_model_name
|
19
|
+
@table_or_model_name ||= model.name.to_s
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -29,13 +29,18 @@ module DatabaseConsistency
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
def project_models
|
33
|
+
ActiveRecord::Base.descendants.select do |klass|
|
34
|
+
project_klass?(klass)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
32
38
|
# Returns list of models to check
|
33
39
|
def models
|
34
|
-
|
40
|
+
project_models.select do |klass|
|
35
41
|
!klass.abstract_class? &&
|
36
42
|
klass.connection.table_exists?(klass.table_name) &&
|
37
|
-
!klass.name.include?('HABTM_')
|
38
|
-
project_klass?(klass)
|
43
|
+
!klass.name.include?('HABTM_')
|
39
44
|
end
|
40
45
|
end
|
41
46
|
|
@@ -8,7 +8,8 @@ module DatabaseConsistency
|
|
8
8
|
Checkers::MissingIndexChecker,
|
9
9
|
Checkers::ForeignKeyChecker,
|
10
10
|
Checkers::ForeignKeyTypeChecker,
|
11
|
-
Checkers::ForeignKeyCascadeChecker
|
11
|
+
Checkers::ForeignKeyCascadeChecker,
|
12
|
+
Checkers::MissingAssociationClassChecker
|
12
13
|
].freeze
|
13
14
|
|
14
15
|
private
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
module Processors
|
5
|
+
# The class to process models
|
6
|
+
class ModelsProcessor < BaseProcessor
|
7
|
+
CHECKERS = [
|
8
|
+
Checkers::MissingTableChecker
|
9
|
+
].freeze
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def check
|
14
|
+
Helper.project_models.flat_map do |model|
|
15
|
+
next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
|
16
|
+
configuration.enabled?(model.name.to_s)
|
17
|
+
|
18
|
+
enabled_checkers.flat_map do |checker_class|
|
19
|
+
checker = checker_class.new(model)
|
20
|
+
checker.report_if_enabled?(configuration)
|
21
|
+
end
|
22
|
+
end.compact
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -33,7 +33,7 @@ module DatabaseConsistency
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def msg
|
36
|
-
|
36
|
+
[report.checker_name, status_text, key_text, message_text].compact.join(' ').strip
|
37
37
|
end
|
38
38
|
|
39
39
|
def unique_key
|
@@ -57,11 +57,14 @@ module DatabaseConsistency
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def key_text
|
60
|
-
|
60
|
+
[
|
61
|
+
colorize(report.table_or_model_name, :blue),
|
62
|
+
colorize(report.column_or_attribute_name, :yellow)
|
63
|
+
].compact.join(' ')
|
61
64
|
end
|
62
65
|
|
63
66
|
def colorize(text, color)
|
64
|
-
return text unless config.colored? && color
|
67
|
+
return text unless text && config.colored? && color
|
65
68
|
|
66
69
|
"#{COLORS[color]}#{text}\e[0m"
|
67
70
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
module Writers
|
5
|
+
module Simple
|
6
|
+
class MissingAssociationClass < Base # :nodoc:
|
7
|
+
private
|
8
|
+
|
9
|
+
def template
|
10
|
+
'refers to undefined model "%<class_name>s"'
|
11
|
+
end
|
12
|
+
|
13
|
+
def unique_attributes
|
14
|
+
{
|
15
|
+
class_name: report.class_name
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def attributes
|
20
|
+
{
|
21
|
+
class_name: report.class_name
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
module Writers
|
5
|
+
module Simple
|
6
|
+
class MissingTable < Base # :nodoc:
|
7
|
+
private
|
8
|
+
|
9
|
+
def template
|
10
|
+
'should have a table in the database'
|
11
|
+
end
|
12
|
+
|
13
|
+
def unique_attributes
|
14
|
+
{
|
15
|
+
table_or_model_name: report.table_or_model_name
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -6,29 +6,31 @@ module DatabaseConsistency
|
|
6
6
|
# The simplest formatter
|
7
7
|
class SimpleWriter < BaseWriter
|
8
8
|
SLUG_TO_WRITER = {
|
9
|
+
association_foreign_type_missing_null_constraint: Simple::AssociationForeignTypeMissingNullConstraint,
|
9
10
|
association_missing_index: Simple::AssociationMissingIndex,
|
10
11
|
association_missing_null_constraint: Simple::AssociationMissingNullConstraint,
|
11
|
-
|
12
|
+
enum_values_inconsistent_with_ar_enum: Simple::EnumValuesInconsistentWithArEnum,
|
13
|
+
enum_values_inconsistent_with_inclusion: Simple::EnumValuesInconsistentWithInclusion,
|
12
14
|
has_one_missing_unique_index: Simple::HasOneMissingUniqueIndex,
|
15
|
+
inconsistent_enum_type: Simple::InconsistentEnumType,
|
13
16
|
inconsistent_types: Simple::InconsistentTypes,
|
14
17
|
length_validator_greater_limit: Simple::LengthValidatorGreaterLimit,
|
15
18
|
length_validator_lower_limit: Simple::LengthValidatorLowerLimit,
|
16
19
|
length_validator_missing: Simple::LengthValidatorMissing,
|
20
|
+
missing_association_class: Simple::MissingAssociationClass,
|
17
21
|
missing_foreign_key: Simple::MissingForeignKey,
|
22
|
+
missing_foreign_key_cascade: Simple::MissingForeignKeyCascade,
|
23
|
+
missing_table: Simple::MissingTable,
|
18
24
|
missing_unique_index: Simple::MissingUniqueIndex,
|
19
25
|
missing_uniqueness_validation: Simple::MissingUniquenessValidation,
|
20
26
|
null_constraint_association_misses_validator: Simple::NullConstraintAssociationMissesValidator,
|
21
27
|
null_constraint_misses_validator: Simple::NullConstraintMissesValidator,
|
22
28
|
null_constraint_missing: Simple::NullConstraintMissing,
|
23
29
|
possible_null: Simple::PossibleNull,
|
30
|
+
redundant_case_insensitive_option: Simple::RedundantCaseInsensitiveOption,
|
24
31
|
redundant_index: Simple::RedundantIndex,
|
25
32
|
redundant_unique_index: Simple::RedundantUniqueIndex,
|
26
33
|
small_primary_key: Simple::SmallPrimaryKey,
|
27
|
-
inconsistent_enum_type: Simple::InconsistentEnumType,
|
28
|
-
missing_foreign_key_cascade: Simple::MissingForeignKeyCascade,
|
29
|
-
enum_values_inconsistent_with_ar_enum: Simple::EnumValuesInconsistentWithArEnum,
|
30
|
-
enum_values_inconsistent_with_inclusion: Simple::EnumValuesInconsistentWithInclusion,
|
31
|
-
redundant_case_insensitive_option: Simple::RedundantCaseInsensitiveOption,
|
32
34
|
three_state_boolean: Simple::ThreeStateBoolean
|
33
35
|
}.freeze
|
34
36
|
|
data/lib/database_consistency.rb
CHANGED
@@ -39,6 +39,8 @@ require 'database_consistency/writers/simple/enum_values_inconsistent_with_ar_en
|
|
39
39
|
require 'database_consistency/writers/simple/enum_values_inconsistent_with_inclusion'
|
40
40
|
require 'database_consistency/writers/simple/redundant_case_insensitive_option'
|
41
41
|
require 'database_consistency/writers/simple/three_state_boolean'
|
42
|
+
require 'database_consistency/writers/simple/missing_association_class'
|
43
|
+
require 'database_consistency/writers/simple/missing_table'
|
42
44
|
require 'database_consistency/writers/simple_writer'
|
43
45
|
|
44
46
|
require 'database_consistency/writers/autofix/helpers/migration'
|
@@ -61,11 +63,15 @@ require 'database_consistency/checkers/base_checker'
|
|
61
63
|
require 'database_consistency/checkers/enum_checkers/enum_checker'
|
62
64
|
require 'database_consistency/checkers/enum_checkers/enum_type_checker'
|
63
65
|
|
66
|
+
require 'database_consistency/checkers/model_checkers/model_checker'
|
67
|
+
require 'database_consistency/checkers/model_checkers/missing_table_checker'
|
68
|
+
|
64
69
|
require 'database_consistency/checkers/association_checkers/association_checker'
|
65
70
|
require 'database_consistency/checkers/association_checkers/missing_index_checker'
|
66
71
|
require 'database_consistency/checkers/association_checkers/foreign_key_checker'
|
67
72
|
require 'database_consistency/checkers/association_checkers/foreign_key_type_checker'
|
68
73
|
require 'database_consistency/checkers/association_checkers/foreign_key_cascade_checker'
|
74
|
+
require 'database_consistency/checkers/association_checkers/missing_association_class_checker'
|
69
75
|
|
70
76
|
require 'database_consistency/checkers/column_checkers/column_checker'
|
71
77
|
require 'database_consistency/checkers/column_checkers/null_constraint_checker'
|
@@ -93,6 +99,7 @@ require 'database_consistency/processors/validators_processor'
|
|
93
99
|
require 'database_consistency/processors/columns_processor'
|
94
100
|
require 'database_consistency/processors/validators_fractions_processor'
|
95
101
|
require 'database_consistency/processors/indexes_processor'
|
102
|
+
require 'database_consistency/processors/models_processor'
|
96
103
|
|
97
104
|
# The root module
|
98
105
|
module DatabaseConsistency
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: database_consistency
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evgeniy Demin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
11
|
+
date: 2023-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- lib/database_consistency/checkers/association_checkers/foreign_key_cascade_checker.rb
|
151
151
|
- lib/database_consistency/checkers/association_checkers/foreign_key_checker.rb
|
152
152
|
- lib/database_consistency/checkers/association_checkers/foreign_key_type_checker.rb
|
153
|
+
- lib/database_consistency/checkers/association_checkers/missing_association_class_checker.rb
|
153
154
|
- lib/database_consistency/checkers/association_checkers/missing_index_checker.rb
|
154
155
|
- lib/database_consistency/checkers/base_checker.rb
|
155
156
|
- lib/database_consistency/checkers/column_checkers/column_checker.rb
|
@@ -164,6 +165,8 @@ files:
|
|
164
165
|
- lib/database_consistency/checkers/index_checkers/redundant_index_checker.rb
|
165
166
|
- lib/database_consistency/checkers/index_checkers/redundant_unique_index_checker.rb
|
166
167
|
- lib/database_consistency/checkers/index_checkers/unique_index_checker.rb
|
168
|
+
- lib/database_consistency/checkers/model_checkers/missing_table_checker.rb
|
169
|
+
- lib/database_consistency/checkers/model_checkers/model_checker.rb
|
167
170
|
- lib/database_consistency/checkers/validator_checkers/case_sensitive_unique_validation_checker.rb
|
168
171
|
- lib/database_consistency/checkers/validator_checkers/missing_unique_index_checker.rb
|
169
172
|
- lib/database_consistency/checkers/validator_checkers/validator_checker.rb
|
@@ -180,6 +183,7 @@ files:
|
|
180
183
|
- lib/database_consistency/processors/columns_processor.rb
|
181
184
|
- lib/database_consistency/processors/enums_processor.rb
|
182
185
|
- lib/database_consistency/processors/indexes_processor.rb
|
186
|
+
- lib/database_consistency/processors/models_processor.rb
|
183
187
|
- lib/database_consistency/processors/validators_fractions_processor.rb
|
184
188
|
- lib/database_consistency/processors/validators_processor.rb
|
185
189
|
- lib/database_consistency/report.rb
|
@@ -217,8 +221,10 @@ files:
|
|
217
221
|
- lib/database_consistency/writers/simple/length_validator_greater_limit.rb
|
218
222
|
- lib/database_consistency/writers/simple/length_validator_lower_limit.rb
|
219
223
|
- lib/database_consistency/writers/simple/length_validator_missing.rb
|
224
|
+
- lib/database_consistency/writers/simple/missing_association_class.rb
|
220
225
|
- lib/database_consistency/writers/simple/missing_foreign_key.rb
|
221
226
|
- lib/database_consistency/writers/simple/missing_foreign_key_cascade.rb
|
227
|
+
- lib/database_consistency/writers/simple/missing_table.rb
|
222
228
|
- lib/database_consistency/writers/simple/missing_unique_index.rb
|
223
229
|
- lib/database_consistency/writers/simple/missing_uniqueness_validation.rb
|
224
230
|
- lib/database_consistency/writers/simple/null_constraint_association_misses_validator.rb
|
@@ -264,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
264
270
|
- !ruby/object:Gem::Version
|
265
271
|
version: '0'
|
266
272
|
requirements: []
|
267
|
-
rubygems_version: 3.1
|
273
|
+
rubygems_version: 3.4.1
|
268
274
|
signing_key:
|
269
275
|
specification_version: 4
|
270
276
|
summary: Provide an easy way to check the consistency of the database constraints
|