database_consistency 1.7.12 → 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: 8560e4cc5588b8182f8d5258703894839190a758abf57e35e2abe81a630848fc
4
- data.tar.gz: 26b96205cd47d48f9a557d6986ef2d2f0eef940f1407ed430760f6201c91cca5
3
+ metadata.gz: 814c6b14aa1b2b510fc2451b0ccc53c22eddcb2954bfe4b870bfbd1788fee2b2
4
+ data.tar.gz: cf6bf9b77bd42a0b149609a36ecb9b0b91f6378353bcb58553dbffd1fccb9a07
5
5
  SHA512:
6
- metadata.gz: bfb1870b761338b23481926ec64cea7a814b7a174937d5035ca6a71ef63f7cfd332db6ab243f15ff5e9990a6445522b5565d2103b0c45eeb147f22eddbc48d7f
7
- data.tar.gz: feec3a2004be04efe8ab1329a79b4b4395ffa3feec5c7798ad04b8218b7365b917a89a80681409d9a1827a5620105a7295ff6b67863828dd85b555c1dc8e7e7f
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DatabaseConsistency
4
- VERSION = '1.7.12'
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.12
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-05 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