database_consistency 1.7.14 → 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/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/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_table.rb +21 -0
- data/lib/database_consistency/writers/simple_writer.rb +1 -0
- data/lib/database_consistency.rb +5 -0
- metadata +6 -2
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
|
@@ -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
|
|
@@ -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,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
|
@@ -20,6 +20,7 @@ module DatabaseConsistency
|
|
20
20
|
missing_association_class: Simple::MissingAssociationClass,
|
21
21
|
missing_foreign_key: Simple::MissingForeignKey,
|
22
22
|
missing_foreign_key_cascade: Simple::MissingForeignKeyCascade,
|
23
|
+
missing_table: Simple::MissingTable,
|
23
24
|
missing_unique_index: Simple::MissingUniqueIndex,
|
24
25
|
missing_uniqueness_validation: Simple::MissingUniquenessValidation,
|
25
26
|
null_constraint_association_misses_validator: Simple::NullConstraintAssociationMissesValidator,
|
data/lib/database_consistency.rb
CHANGED
@@ -40,6 +40,7 @@ require 'database_consistency/writers/simple/enum_values_inconsistent_with_inclu
|
|
40
40
|
require 'database_consistency/writers/simple/redundant_case_insensitive_option'
|
41
41
|
require 'database_consistency/writers/simple/three_state_boolean'
|
42
42
|
require 'database_consistency/writers/simple/missing_association_class'
|
43
|
+
require 'database_consistency/writers/simple/missing_table'
|
43
44
|
require 'database_consistency/writers/simple_writer'
|
44
45
|
|
45
46
|
require 'database_consistency/writers/autofix/helpers/migration'
|
@@ -62,6 +63,9 @@ require 'database_consistency/checkers/base_checker'
|
|
62
63
|
require 'database_consistency/checkers/enum_checkers/enum_checker'
|
63
64
|
require 'database_consistency/checkers/enum_checkers/enum_type_checker'
|
64
65
|
|
66
|
+
require 'database_consistency/checkers/model_checkers/model_checker'
|
67
|
+
require 'database_consistency/checkers/model_checkers/missing_table_checker'
|
68
|
+
|
65
69
|
require 'database_consistency/checkers/association_checkers/association_checker'
|
66
70
|
require 'database_consistency/checkers/association_checkers/missing_index_checker'
|
67
71
|
require 'database_consistency/checkers/association_checkers/foreign_key_checker'
|
@@ -95,6 +99,7 @@ require 'database_consistency/processors/validators_processor'
|
|
95
99
|
require 'database_consistency/processors/columns_processor'
|
96
100
|
require 'database_consistency/processors/validators_fractions_processor'
|
97
101
|
require 'database_consistency/processors/indexes_processor'
|
102
|
+
require 'database_consistency/processors/models_processor'
|
98
103
|
|
99
104
|
# The root module
|
100
105
|
module DatabaseConsistency
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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
|
@@ -165,6 +165,8 @@ files:
|
|
165
165
|
- lib/database_consistency/checkers/index_checkers/redundant_index_checker.rb
|
166
166
|
- lib/database_consistency/checkers/index_checkers/redundant_unique_index_checker.rb
|
167
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
|
168
170
|
- lib/database_consistency/checkers/validator_checkers/case_sensitive_unique_validation_checker.rb
|
169
171
|
- lib/database_consistency/checkers/validator_checkers/missing_unique_index_checker.rb
|
170
172
|
- lib/database_consistency/checkers/validator_checkers/validator_checker.rb
|
@@ -181,6 +183,7 @@ files:
|
|
181
183
|
- lib/database_consistency/processors/columns_processor.rb
|
182
184
|
- lib/database_consistency/processors/enums_processor.rb
|
183
185
|
- lib/database_consistency/processors/indexes_processor.rb
|
186
|
+
- lib/database_consistency/processors/models_processor.rb
|
184
187
|
- lib/database_consistency/processors/validators_fractions_processor.rb
|
185
188
|
- lib/database_consistency/processors/validators_processor.rb
|
186
189
|
- lib/database_consistency/report.rb
|
@@ -221,6 +224,7 @@ files:
|
|
221
224
|
- lib/database_consistency/writers/simple/missing_association_class.rb
|
222
225
|
- lib/database_consistency/writers/simple/missing_foreign_key.rb
|
223
226
|
- lib/database_consistency/writers/simple/missing_foreign_key_cascade.rb
|
227
|
+
- lib/database_consistency/writers/simple/missing_table.rb
|
224
228
|
- lib/database_consistency/writers/simple/missing_unique_index.rb
|
225
229
|
- lib/database_consistency/writers/simple/missing_uniqueness_validation.rb
|
226
230
|
- lib/database_consistency/writers/simple/null_constraint_association_misses_validator.rb
|
@@ -266,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
266
270
|
- !ruby/object:Gem::Version
|
267
271
|
version: '0'
|
268
272
|
requirements: []
|
269
|
-
rubygems_version: 3.
|
273
|
+
rubygems_version: 3.4.1
|
270
274
|
signing_key:
|
271
275
|
specification_version: 4
|
272
276
|
summary: Provide an easy way to check the consistency of the database constraints
|