database_consistency 1.7.11 → 1.7.13

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: bf8618ba8f3e8311f6cfe28281eb840f72fb389267d23c7df8dacceb81466856
4
- data.tar.gz: 14b60dbacd605899a0f1e5c95147b1f879d36ff70bcf761f867412697093d552
3
+ metadata.gz: 814c6b14aa1b2b510fc2451b0ccc53c22eddcb2954bfe4b870bfbd1788fee2b2
4
+ data.tar.gz: cf6bf9b77bd42a0b149609a36ecb9b0b91f6378353bcb58553dbffd1fccb9a07
5
5
  SHA512:
6
- metadata.gz: 368509ce28357a3817a1f8c05233db99b9baa451b70e28fc484d2ea87e1745de08a65c0aff88dfc71d730b8fcd5932565b685b97d1a32b224faf9f494413055c
7
- data.tar.gz: d8f1272dfabd6d7531efe1d37fd13924bedf734bf4def4274c24c8bc0d85e616a6b2c391e8594f32051e3a5cba15cb19d3aab2c6a8b682d48b1d928f21c95c00
6
+ metadata.gz: f4f002828a20fa7376346ed94bd63908a01f572aa2fa20ea452918f391baf2ad4ac7c0e72d98d784fab0003cfd4b3de36589ca29d01c9ae34951c55740fb2372
7
+ data.tar.gz: 68fabfbd7d75b68b8a404e57dc490d7c2e0ef30a70a76f84f08c28130a58975ad80c1ba2dd59cc1589cd7c3090a21e62ad1a6f29dd15ff013e36676be6faa42f
@@ -22,6 +22,8 @@ module DatabaseConsistency
22
22
  supported? &&
23
23
  association.belongs_to? && !association.polymorphic? &&
24
24
  same_database?
25
+ rescue NameError
26
+ false
25
27
  end
26
28
 
27
29
  def same_database?
@@ -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
@@ -9,7 +9,11 @@ module DatabaseConsistency
9
9
 
10
10
  def initialize(file_paths = DEFAULT_PATH)
11
11
  @configuration = existing_configurations(file_paths).then do |existing_paths|
12
- puts "Loaded configurations: #{existing_paths.join(', ')}"
12
+ if existing_paths.any?
13
+ puts "Loaded configurations: #{existing_paths.join(', ')}"
14
+ else
15
+ puts 'No configurations were provided'
16
+ end
13
17
  extract_configurations(existing_paths)
14
18
  end
15
19
  end
@@ -13,6 +13,10 @@ module DatabaseConsistency
13
13
  end
14
14
  end
15
15
 
16
+ def database_name(model)
17
+ model.connection_db_config.name.to_s if model.respond_to?(:connection_db_config)
18
+ end
19
+
16
20
  def postgresql?
17
21
  adapter == 'postgresql'
18
22
  end
@@ -8,14 +8,16 @@ 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
15
16
 
16
- def check
17
+ def check # rubocop:disable Metrics/AbcSize
17
18
  Helper.models.flat_map do |model|
18
- next unless configuration.enabled?(model.name.to_s)
19
+ next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
20
+ configuration.enabled?(model.name.to_s)
19
21
 
20
22
  Helper.first_level_associations(model).flat_map do |association|
21
23
  enabled_checkers.flat_map do |checker_class|
@@ -14,9 +14,10 @@ module DatabaseConsistency
14
14
 
15
15
  private
16
16
 
17
- def check
17
+ def check # rubocop:disable Metrics/AbcSize
18
18
  Helper.parent_models.flat_map do |model|
19
- next unless configuration.enabled?(model.name.to_s)
19
+ next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
20
+ configuration.enabled?(model.name.to_s)
20
21
 
21
22
  model.columns.flat_map do |column|
22
23
  enabled_checkers.flat_map do |checker_class|
@@ -10,9 +10,10 @@ module DatabaseConsistency
10
10
 
11
11
  private
12
12
 
13
- def check
13
+ def check # rubocop:disable Metrics/AbcSize
14
14
  Helper.models.flat_map do |model|
15
- next unless configuration.enabled?(model.name.to_s)
15
+ next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
16
+ configuration.enabled?(model.name.to_s)
16
17
 
17
18
  model.defined_enums.keys.flat_map do |enum|
18
19
  enabled_checkers.flat_map do |checker_class|
@@ -14,7 +14,8 @@ module DatabaseConsistency
14
14
 
15
15
  def check # rubocop:disable Metrics/AbcSize
16
16
  Helper.parent_models.flat_map do |model|
17
- next unless configuration.enabled?(model.name.to_s)
17
+ next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
18
+ configuration.enabled?(model.name.to_s)
18
19
 
19
20
  indexes = model.connection.indexes(model.table_name)
20
21
 
@@ -11,9 +11,10 @@ module DatabaseConsistency
11
11
  private
12
12
 
13
13
  # @return [Array<Hash>]
14
- def check
14
+ def check # rubocop:disable Metrics/AbcSize
15
15
  Helper.parent_models.flat_map do |model|
16
- next unless configuration.enabled?(model.name.to_s)
16
+ next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
17
+ configuration.enabled?(model.name.to_s)
17
18
 
18
19
  model._validators.flat_map do |attribute, validators|
19
20
  next unless attribute
@@ -12,9 +12,10 @@ module DatabaseConsistency
12
12
  private
13
13
 
14
14
  # @return [Array<Hash>]
15
- def check # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
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?(model.name.to_s)
17
+ next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
18
+ configuration.enabled?(model.name.to_s)
18
19
 
19
20
  model.validators.flat_map do |validator|
20
21
  next unless validator.respond_to?(:attributes)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DatabaseConsistency
4
- VERSION = '1.7.11'
4
+ VERSION = '1.7.13'
5
5
  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
@@ -6,29 +6,30 @@ 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
- association_foreign_type_missing_null_constraint: Simple::AssociationForeignTypeMissingNullConstraint,
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,
18
23
  missing_unique_index: Simple::MissingUniqueIndex,
19
24
  missing_uniqueness_validation: Simple::MissingUniquenessValidation,
20
25
  null_constraint_association_misses_validator: Simple::NullConstraintAssociationMissesValidator,
21
26
  null_constraint_misses_validator: Simple::NullConstraintMissesValidator,
22
27
  null_constraint_missing: Simple::NullConstraintMissing,
23
28
  possible_null: Simple::PossibleNull,
29
+ redundant_case_insensitive_option: Simple::RedundantCaseInsensitiveOption,
24
30
  redundant_index: Simple::RedundantIndex,
25
31
  redundant_unique_index: Simple::RedundantUniqueIndex,
26
32
  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
33
  three_state_boolean: Simple::ThreeStateBoolean
33
34
  }.freeze
34
35
 
@@ -39,6 +39,7 @@ 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'
42
43
  require 'database_consistency/writers/simple_writer'
43
44
 
44
45
  require 'database_consistency/writers/autofix/helpers/migration'
@@ -66,6 +67,7 @@ require 'database_consistency/checkers/association_checkers/missing_index_checke
66
67
  require 'database_consistency/checkers/association_checkers/foreign_key_checker'
67
68
  require 'database_consistency/checkers/association_checkers/foreign_key_type_checker'
68
69
  require 'database_consistency/checkers/association_checkers/foreign_key_cascade_checker'
70
+ require 'database_consistency/checkers/association_checkers/missing_association_class_checker'
69
71
 
70
72
  require 'database_consistency/checkers/column_checkers/column_checker'
71
73
  require 'database_consistency/checkers/column_checkers/null_constraint_checker'
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.11
4
+ version: 1.7.13
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-01 00:00:00.000000000 Z
11
+ date: 2023-07-09 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
@@ -217,6 +218,7 @@ files:
217
218
  - lib/database_consistency/writers/simple/length_validator_greater_limit.rb
218
219
  - lib/database_consistency/writers/simple/length_validator_lower_limit.rb
219
220
  - lib/database_consistency/writers/simple/length_validator_missing.rb
221
+ - lib/database_consistency/writers/simple/missing_association_class.rb
220
222
  - lib/database_consistency/writers/simple/missing_foreign_key.rb
221
223
  - lib/database_consistency/writers/simple/missing_foreign_key_cascade.rb
222
224
  - lib/database_consistency/writers/simple/missing_unique_index.rb
@@ -264,7 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
264
266
  - !ruby/object:Gem::Version
265
267
  version: '0'
266
268
  requirements: []
267
- rubygems_version: 3.1.6
269
+ rubygems_version: 3.2.33
268
270
  signing_key:
269
271
  specification_version: 4
270
272
  summary: Provide an easy way to check the consistency of the database constraints