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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3621ad7d1790987ba3867541950d611af17e26be2da7bbc1a33914db25292872
4
- data.tar.gz: 8d26e698a1c2ca1f8ba37e2ca899b3486730a025e7b4377645603eda312c0d59
3
+ metadata.gz: 8218744cf4be81d5348c01ffbb18c545b0c98db3a864575de8046b0c15d43002
4
+ data.tar.gz: 6a311b65d72845d0bb746d6d93c5f8850e2056202b042a015c4ea900f30c70f4
5
5
  SHA512:
6
- metadata.gz: aedb071d671ca0a4b92a060c58aced55e4e49039d80fbb8d0fc6aa2062070763d5ae4d08333c32cdc3c65fcdb4bf7798875076b47d342c541d1e73ce7c3e57d3
7
- data.tar.gz: 82c070e44a36db48e84f17f701168d2fc02f019bd61dcdc9fa43d2cd79039eb865f8466215a75940a66b0cc782417a5adfe47394e4ed1b046164a6e43ce89092
6
+ metadata.gz: 85832321274f953b83db7ca119b07bd812c983adeabf3ce9be69291bd8cbb29afef6630a9e90599be82f40f68538e878f599cdfbdd19e705dd38bba0ee5fd54d
7
+ data.tar.gz: a5738e4667fabca642f76d0be5dff2618bede457681d6b26cbf16f2b0fdb63fa526c068baf87026d0773c476bcd442a3de70fd119fce9f68e9c60ff2e7bb0fad
@@ -27,10 +27,16 @@ module DatabaseConsistency
27
27
  status: status,
28
28
  error_message: nil,
29
29
  error_slug: error_slug,
30
- class_name: association.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
- next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
20
- configuration.enabled?(model.name.to_s)
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
- Helper.first_level_associations(model).flat_map do |association|
23
- enabled_checkers.flat_map do |checker_class|
24
- checker = checker_class.new(model, association)
25
- checker.report_if_enabled?(configuration)
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
- next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
20
- configuration.enabled?(model.name.to_s)
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
- model.columns.flat_map do |column|
23
- enabled_checkers.flat_map do |checker_class|
24
- checker = checker_class.new(model, column)
25
- checker.report_if_enabled?(configuration)
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
- next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
16
- configuration.enabled?(model.name.to_s)
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
- model.defined_enums.keys.flat_map do |enum|
19
- enabled_checkers.flat_map do |checker_class|
20
- checker = checker_class.new(model, enum)
21
- checker.report_if_enabled?(configuration)
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
- next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
18
- configuration.enabled?(model.name.to_s)
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
- indexes = model.connection.indexes(model.table_name)
21
+ indexes = model.connection.indexes(model.table_name)
21
22
 
22
- indexes.flat_map do |index|
23
- enabled_checkers.flat_map do |checker_class|
24
- checker = checker_class.new(model, index)
25
- checker.report_if_enabled?(configuration)
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
- next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
16
- configuration.enabled?(model.name.to_s)
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
- enabled_checkers.flat_map do |checker_class|
19
- checker = checker_class.new(model)
20
- checker.report_if_enabled?(configuration)
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
- next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
17
- configuration.enabled?(model.name.to_s)
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
- model._validators.flat_map do |attribute, validators|
20
- next unless attribute
20
+ model._validators.flat_map do |attribute, validators|
21
+ DebugContext.with(attribute: attribute) do
22
+ next unless attribute
21
23
 
22
- enabled_checkers.flat_map do |checker_class|
23
- checker = checker_class.new(model, attribute, validators)
24
- checker.report_if_enabled?(configuration)
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
- next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
18
- configuration.enabled?(model.name.to_s)
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
- model.validators.flat_map do |validator|
21
- next unless validator.respond_to?(:attributes)
21
+ model.validators.flat_map do |validator|
22
+ next unless validator.respond_to?(:attributes)
22
23
 
23
- validator.attributes.flat_map do |attribute|
24
- enabled_checkers.flat_map do |checker_class|
25
- checker = checker_class.new(model, attribute, validator)
26
- checker.report_if_enabled?(configuration)
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  module DatabaseConsistency
4
4
  class ReportBuilder # :nodoc:
5
- def self.define(klass, *attrs) # rubocop:disable Metrics/MethodLength
5
+ def self.define(klass, *attrs)
6
6
  Class.new(klass) do
7
7
  attr_reader(*attrs)
8
8
 
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DatabaseConsistency
4
- VERSION = '1.7.15'
4
+ VERSION = '1.7.17'
5
5
  end
@@ -7,7 +7,7 @@ module DatabaseConsistency
7
7
  private
8
8
 
9
9
  def template
10
- 'refers to undefined model "%<class_name>s"'
10
+ 'refers to undefined model %<class_name>s'
11
11
  end
12
12
 
13
13
  def unique_attributes
@@ -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.15
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-13 00:00:00.000000000 Z
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