database_consistency 1.7.15 → 1.7.17
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/missing_association_class_checker.rb +7 -1
- data/lib/database_consistency/debug_context.rb +44 -0
- data/lib/database_consistency/processors/associations_processor.rb +13 -7
- data/lib/database_consistency/processors/columns_processor.rb +13 -7
- data/lib/database_consistency/processors/enums_processor.rb +13 -7
- data/lib/database_consistency/processors/indexes_processor.rb +14 -8
- data/lib/database_consistency/processors/models_processor.rb +10 -6
- data/lib/database_consistency/processors/validators_fractions_processor.rb +14 -8
- data/lib/database_consistency/processors/validators_processor.rb +14 -8
- data/lib/database_consistency/report_builder.rb +1 -1
- data/lib/database_consistency/rescue_error.rb +3 -0
- data/lib/database_consistency/version.rb +1 -1
- data/lib/database_consistency/writers/simple/missing_association_class.rb +1 -1
- data/lib/database_consistency.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8218744cf4be81d5348c01ffbb18c545b0c98db3a864575de8046b0c15d43002
|
4
|
+
data.tar.gz: 6a311b65d72845d0bb746d6d93c5f8850e2056202b042a015c4ea900f30c70f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85832321274f953b83db7ca119b07bd812c983adeabf3ce9be69291bd8cbb29afef6630a9e90599be82f40f68538e878f599cdfbdd19e705dd38bba0ee5fd54d
|
7
|
+
data.tar.gz: a5738e4667fabca642f76d0be5dff2618bede457681d6b26cbf16f2b0fdb63fa526c068baf87026d0773c476bcd442a3de70fd119fce9f68e9c60ff2e7bb0fad
|
data/lib/database_consistency/checkers/association_checkers/missing_association_class_checker.rb
CHANGED
@@ -27,10 +27,16 @@ module DatabaseConsistency
|
|
27
27
|
status: status,
|
28
28
|
error_message: nil,
|
29
29
|
error_slug: error_slug,
|
30
|
-
class_name:
|
30
|
+
class_name: class_name,
|
31
31
|
**report_attributes
|
32
32
|
)
|
33
33
|
end
|
34
|
+
|
35
|
+
def class_name
|
36
|
+
association.class_name
|
37
|
+
rescue NoMethodError
|
38
|
+
nil
|
39
|
+
end
|
34
40
|
end
|
35
41
|
end
|
36
42
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
# The container that stores information for debugging purposes
|
5
|
+
class DebugContext
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
self.class.delegate :with, to: :instance
|
9
|
+
self.class.delegate :output, to: :instance
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
clear!
|
13
|
+
end
|
14
|
+
|
15
|
+
def with(context)
|
16
|
+
context.each do |key, value|
|
17
|
+
store[key] = value
|
18
|
+
end
|
19
|
+
|
20
|
+
result = yield
|
21
|
+
|
22
|
+
context.each_key do |key|
|
23
|
+
store.delete(key)
|
24
|
+
end
|
25
|
+
|
26
|
+
result
|
27
|
+
end
|
28
|
+
|
29
|
+
def output(destination)
|
30
|
+
store.each do |key, value|
|
31
|
+
destination.puts("#{key}: #{value}")
|
32
|
+
end
|
33
|
+
clear!
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
attr_reader :store
|
39
|
+
|
40
|
+
def clear!
|
41
|
+
@store = {}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -14,15 +14,21 @@ module DatabaseConsistency
|
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
-
def check # rubocop:disable Metrics/AbcSize
|
17
|
+
def check # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
18
18
|
Helper.models.flat_map do |model|
|
19
|
-
|
20
|
-
|
19
|
+
DebugContext.with(model: model.name) do
|
20
|
+
next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
|
21
|
+
configuration.enabled?(model.name.to_s)
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
Helper.first_level_associations(model).flat_map do |association|
|
24
|
+
DebugContext.with(association: association.name) do
|
25
|
+
enabled_checkers.flat_map do |checker_class|
|
26
|
+
DebugContext.with(checker: checker_class) do
|
27
|
+
checker = checker_class.new(model, association)
|
28
|
+
checker.report_if_enabled?(configuration)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
26
32
|
end
|
27
33
|
end
|
28
34
|
end.compact
|
@@ -14,15 +14,21 @@ module DatabaseConsistency
|
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
-
def check # rubocop:disable Metrics/AbcSize
|
17
|
+
def check # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
18
18
|
Helper.parent_models.flat_map do |model|
|
19
|
-
|
20
|
-
|
19
|
+
DebugContext.with(model: model.name) do
|
20
|
+
next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
|
21
|
+
configuration.enabled?(model.name.to_s)
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
model.columns.flat_map do |column|
|
24
|
+
DebugContext.with(column: column.name) do
|
25
|
+
enabled_checkers.flat_map do |checker_class|
|
26
|
+
DebugContext.with(checker: checker_class) do
|
27
|
+
checker = checker_class.new(model, column)
|
28
|
+
checker.report_if_enabled?(configuration)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
26
32
|
end
|
27
33
|
end
|
28
34
|
end.compact
|
@@ -10,15 +10,21 @@ module DatabaseConsistency
|
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
|
-
def check # rubocop:disable Metrics/AbcSize
|
13
|
+
def check # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
14
14
|
Helper.models.flat_map do |model|
|
15
|
-
|
16
|
-
|
15
|
+
DebugContext.with(model: model.name) do
|
16
|
+
next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
|
17
|
+
configuration.enabled?(model.name.to_s)
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
model.defined_enums.keys.flat_map do |enum|
|
20
|
+
DebugContext.with(enum: enum) do
|
21
|
+
enabled_checkers.flat_map do |checker_class|
|
22
|
+
DebugContext.with(checker: checker_class) do
|
23
|
+
checker = checker_class.new(model, enum)
|
24
|
+
checker.report_if_enabled?(configuration)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
22
28
|
end
|
23
29
|
end
|
24
30
|
end.compact
|
@@ -12,17 +12,23 @@ module DatabaseConsistency
|
|
12
12
|
|
13
13
|
private
|
14
14
|
|
15
|
-
def check # rubocop:disable Metrics/AbcSize
|
15
|
+
def check # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
16
16
|
Helper.parent_models.flat_map do |model|
|
17
|
-
|
18
|
-
|
17
|
+
DebugContext.with(model: model.name) do
|
18
|
+
next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
|
19
|
+
configuration.enabled?(model.name.to_s)
|
19
20
|
|
20
|
-
|
21
|
+
indexes = model.connection.indexes(model.table_name)
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
indexes.flat_map do |index|
|
24
|
+
DebugContext.with(index: index.name) do
|
25
|
+
enabled_checkers.flat_map do |checker_class|
|
26
|
+
DebugContext.with(checker: checker_class) do
|
27
|
+
checker = checker_class.new(model, index)
|
28
|
+
checker.report_if_enabled?(configuration)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
26
32
|
end
|
27
33
|
end
|
28
34
|
end.compact
|
@@ -10,14 +10,18 @@ module DatabaseConsistency
|
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
|
-
def check
|
13
|
+
def check # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
14
14
|
Helper.project_models.flat_map do |model|
|
15
|
-
|
16
|
-
|
15
|
+
DebugContext.with(model: model.name) do
|
16
|
+
next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
|
17
|
+
configuration.enabled?(model.name.to_s)
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
enabled_checkers.flat_map do |checker_class|
|
20
|
+
DebugContext.with(checker: checker_class) do
|
21
|
+
checker = checker_class.new(model)
|
22
|
+
checker.report_if_enabled?(configuration)
|
23
|
+
end
|
24
|
+
end
|
21
25
|
end
|
22
26
|
end.compact
|
23
27
|
end
|
@@ -11,17 +11,23 @@ module DatabaseConsistency
|
|
11
11
|
private
|
12
12
|
|
13
13
|
# @return [Array<Hash>]
|
14
|
-
def check # rubocop:disable Metrics/AbcSize
|
14
|
+
def check # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
15
15
|
Helper.parent_models.flat_map do |model|
|
16
|
-
|
17
|
-
|
16
|
+
DebugContext.with(model: model.name) do
|
17
|
+
next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
|
18
|
+
configuration.enabled?(model.name.to_s)
|
18
19
|
|
19
|
-
|
20
|
-
|
20
|
+
model._validators.flat_map do |attribute, validators|
|
21
|
+
DebugContext.with(attribute: attribute) do
|
22
|
+
next unless attribute
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
enabled_checkers.flat_map do |checker_class|
|
25
|
+
DebugContext.with(checker: checker_class) do
|
26
|
+
checker = checker_class.new(model, attribute, validators)
|
27
|
+
checker.report_if_enabled?(configuration)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
25
31
|
end
|
26
32
|
end
|
27
33
|
end.compact
|
@@ -14,16 +14,22 @@ module DatabaseConsistency
|
|
14
14
|
# @return [Array<Hash>]
|
15
15
|
def check # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
|
16
16
|
Helper.parent_models.flat_map do |model|
|
17
|
-
|
18
|
-
|
17
|
+
DebugContext.with(model: model.name) do
|
18
|
+
next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
|
19
|
+
configuration.enabled?(model.name.to_s)
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
model.validators.flat_map do |validator|
|
22
|
+
next unless validator.respond_to?(:attributes)
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
validator.attributes.flat_map do |attribute|
|
25
|
+
DebugContext.with(attribute: attribute) do
|
26
|
+
enabled_checkers.flat_map do |checker_class|
|
27
|
+
DebugContext.with(checker: checker_class) do
|
28
|
+
checker = checker_class.new(model, attribute, validator)
|
29
|
+
checker.report_if_enabled?(configuration)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
27
33
|
end
|
28
34
|
end
|
29
35
|
end
|
@@ -25,6 +25,9 @@ module DatabaseConsistency
|
|
25
25
|
def call(error)
|
26
26
|
File.open(filename, 'a') do |file|
|
27
27
|
file.puts('<===begin===>')
|
28
|
+
file.puts('Metadata:')
|
29
|
+
DebugContext.output(file)
|
30
|
+
file.puts('Stack trace:')
|
28
31
|
file.puts(error.full_message)
|
29
32
|
file.puts('<===end===>')
|
30
33
|
end
|
data/lib/database_consistency.rb
CHANGED
@@ -9,6 +9,7 @@ require 'database_consistency/rescue_error'
|
|
9
9
|
require 'database_consistency/errors'
|
10
10
|
require 'database_consistency/report_builder'
|
11
11
|
require 'database_consistency/report'
|
12
|
+
require 'database_consistency/debug_context'
|
12
13
|
|
13
14
|
require 'database_consistency/writers/base_writer'
|
14
15
|
require 'database_consistency/writers/todo_writer'
|
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.17
|
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-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -176,6 +176,7 @@ files:
|
|
176
176
|
- lib/database_consistency/databases/factory.rb
|
177
177
|
- lib/database_consistency/databases/types/base.rb
|
178
178
|
- lib/database_consistency/databases/types/sqlite.rb
|
179
|
+
- lib/database_consistency/debug_context.rb
|
179
180
|
- lib/database_consistency/errors.rb
|
180
181
|
- lib/database_consistency/helper.rb
|
181
182
|
- lib/database_consistency/processors/associations_processor.rb
|