database_consistency 1.7.27 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ba4d8b566474e443336b5b7c471ad85bb492581847cb721daa5ba41be272bc0
4
- data.tar.gz: c5c80cbfd15eae2e8b948cc44233d1c2c74a67a734ee0867a30defd3ed8a877d
3
+ metadata.gz: ba84801df64868302240abb6b325652bc21c34086c2b4d32460bb092f55d7681
4
+ data.tar.gz: 49ba63ec3857648e90121ef8e7692fe217fcb41592b21087876628caa7888427
5
5
  SHA512:
6
- metadata.gz: 5d49d5e2e5f15577114ae6adaa8453db9ad9573bd0af6f0bc2eafb8319b30a04fae8f7ef6005e7c5990da1686d79a1d5e58ac535a182152767bf68764daf4edb
7
- data.tar.gz: f9a07275157c90e2e20b04706a5f6b95974918d7c0716ea16f91cd2737a4b60bc0a82b65f9f2e8a286c1f9d3976d1d0f4f78b0dabc832079c37644010a8563d6
6
+ metadata.gz: f29ab6930f1317041b38879890a0195ed03d7620647a08baa5061fd82cd5b124587f0acafa9fe15b1d92747b4a8e7f05528fb4882b170cdf6feb23ed326547aa
7
+ data.tar.gz: a4e7fb560d24c41aa1dc02ad3127658ac9ab6f268be885843ca03cf24bc49e4354cec95f8d78a69ad44579eaef984a555c578e347eb98645de27248c75edfe3e
@@ -21,7 +21,8 @@ module DatabaseConsistency
21
21
  def preconditions
22
22
  supported? &&
23
23
  association.belongs_to? && !association.polymorphic? &&
24
- same_database?
24
+ same_database? &&
25
+ model.connection.table_exists?(model.table_name)
25
26
  rescue NameError
26
27
  false
27
28
  end
@@ -11,9 +11,19 @@ module DatabaseConsistency
11
11
  configuration.enabled?('DatabaseConsistencyCheckers', checker_name)
12
12
  end
13
13
 
14
+ def self.inherited(subclass)
15
+ super
16
+
17
+ return if subclass.superclass.name == 'DatabaseConsistency::Checkers::BaseChecker'
18
+
19
+ processor_prefix = subclass.superclass.name.demodulize.delete_suffix('Checker').pluralize
20
+ processor = "DatabaseConsistency::Processors::#{processor_prefix}Processor".constantize
21
+ processor.checkers << subclass
22
+ end
23
+
14
24
  # @return [String]
15
25
  def self.checker_name
16
- @checker_name ||= name.split('::').last
26
+ @checker_name ||= name.demodulize
17
27
  end
18
28
 
19
29
  # @param [Boolean] catch_errors
@@ -12,8 +12,9 @@ module DatabaseConsistency
12
12
 
13
13
  private
14
14
 
15
+ # column should be a boolean and table shouldn't be a view
15
16
  def preconditions
16
- column.type == :boolean
17
+ column.type == :boolean && model.connection.table_exists?(model.table_name)
17
18
  end
18
19
 
19
20
  def check
@@ -19,7 +19,7 @@ module DatabaseConsistency
19
19
  end
20
20
 
21
21
  def preconditions
22
- (regular_column || association) && validators.any?
22
+ (regular_column || association) && model.connection.table_exists?(model.table_name) && validators.any?
23
23
  end
24
24
 
25
25
  def report_template(status, column_name:, error_slug: nil)
@@ -16,6 +16,8 @@ module DatabaseConsistency
16
16
  end
17
17
  extract_configurations(existing_paths)
18
18
  end
19
+
20
+ load_custom_checkers
19
21
  end
20
22
 
21
23
  def debug?
@@ -123,5 +125,13 @@ module DatabaseConsistency
123
125
  settings && settings['log_level']
124
126
  end
125
127
  end
128
+
129
+ def load_custom_checkers
130
+ return unless configuration.key?('require') && configuration['require'].is_a?(Array)
131
+
132
+ configuration['require'].each do |path|
133
+ require path
134
+ end
135
+ end
126
136
  end
127
137
  end
@@ -4,14 +4,6 @@ module DatabaseConsistency
4
4
  module Processors
5
5
  # The class to process associations
6
6
  class AssociationsProcessor < BaseProcessor
7
- CHECKERS = [
8
- Checkers::MissingIndexChecker,
9
- Checkers::ForeignKeyChecker,
10
- Checkers::ForeignKeyTypeChecker,
11
- Checkers::ForeignKeyCascadeChecker,
12
- Checkers::MissingAssociationClassChecker
13
- ].freeze
14
-
15
7
  private
16
8
 
17
9
  def check # rubocop:disable Metrics/MethodLength
@@ -4,21 +4,17 @@ module DatabaseConsistency
4
4
  # The module for processors
5
5
  module Processors
6
6
  def self.reports(configuration)
7
- [
8
- ColumnsProcessor,
9
- ValidatorsProcessor,
10
- AssociationsProcessor,
11
- ValidatorsFractionsProcessor,
12
- IndexesProcessor,
13
- EnumsProcessor,
14
- ModelsProcessor
15
- ].flat_map do |processor|
7
+ BaseProcessor.descendants.flat_map do |processor|
16
8
  processor.new(configuration).reports
17
9
  end
18
10
  end
19
11
 
20
12
  # The base class for processors
21
13
  class BaseProcessor
14
+ def self.checkers
15
+ @checkers ||= Set.new
16
+ end
17
+
22
18
  attr_reader :configuration
23
19
 
24
20
  # @param [DatabaseConsistency::Configuration] configuration
@@ -38,7 +34,7 @@ module DatabaseConsistency
38
34
 
39
35
  # @return [Array<Class>]
40
36
  def enabled_checkers
41
- self.class::CHECKERS.select { |checker| checker.enabled?(configuration) }
37
+ self.class.checkers.select { |checker| checker.enabled?(configuration) }
42
38
  end
43
39
 
44
40
  private
@@ -4,15 +4,6 @@ module DatabaseConsistency
4
4
  module Processors
5
5
  # The class to process columns
6
6
  class ColumnsProcessor < BaseProcessor
7
- CHECKERS = [
8
- Checkers::NullConstraintChecker,
9
- Checkers::LengthConstraintChecker,
10
- Checkers::PrimaryKeyTypeChecker,
11
- Checkers::EnumValueChecker,
12
- Checkers::ThreeStateBooleanChecker,
13
- Checkers::ImplicitOrderingChecker
14
- ].freeze
15
-
16
7
  private
17
8
 
18
9
  def check # rubocop:disable Metrics/MethodLength
@@ -4,10 +4,6 @@ module DatabaseConsistency
4
4
  module Processors
5
5
  # The class to process enums
6
6
  class EnumsProcessor < BaseProcessor
7
- CHECKERS = [
8
- Checkers::EnumTypeChecker
9
- ].freeze
10
-
11
7
  private
12
8
 
13
9
  def check # rubocop:disable Metrics/MethodLength
@@ -4,12 +4,6 @@ module DatabaseConsistency
4
4
  module Processors
5
5
  # The class to process indexes
6
6
  class IndexesProcessor < BaseProcessor
7
- CHECKERS = [
8
- Checkers::UniqueIndexChecker,
9
- Checkers::RedundantIndexChecker,
10
- Checkers::RedundantUniqueIndexChecker
11
- ].freeze
12
-
13
7
  private
14
8
 
15
9
  def check # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
@@ -4,10 +4,6 @@ module DatabaseConsistency
4
4
  module Processors
5
5
  # The class to process models
6
6
  class ModelsProcessor < BaseProcessor
7
- CHECKERS = [
8
- Checkers::MissingTableChecker
9
- ].freeze
10
-
11
7
  private
12
8
 
13
9
  def check
@@ -4,10 +4,6 @@ module DatabaseConsistency
4
4
  module Processors
5
5
  # The class to process validators
6
6
  class ValidatorsFractionsProcessor < BaseProcessor
7
- CHECKERS = [
8
- Checkers::ColumnPresenceChecker
9
- ].freeze
10
-
11
7
  private
12
8
 
13
9
  # @return [Array<Hash>]
@@ -4,11 +4,6 @@ module DatabaseConsistency
4
4
  module Processors
5
5
  # The class to process validators
6
6
  class ValidatorsProcessor < BaseProcessor
7
- CHECKERS = [
8
- Checkers::MissingUniqueIndexChecker,
9
- Checkers::CaseSensitiveUniqueValidationChecker
10
- ].freeze
11
-
12
7
  private
13
8
 
14
9
  # @return [Array<Hash>]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DatabaseConsistency
4
- VERSION = '1.7.27'
4
+ VERSION = '2.0.1'
5
5
  end
@@ -5,36 +5,6 @@ module DatabaseConsistency
5
5
  module Writers
6
6
  # The simplest formatter
7
7
  class SimpleWriter < BaseWriter
8
- SLUG_TO_WRITER = {
9
- association_foreign_type_missing_null_constraint: Simple::AssociationForeignTypeMissingNullConstraint,
10
- association_missing_index: Simple::AssociationMissingIndex,
11
- association_missing_null_constraint: Simple::AssociationMissingNullConstraint,
12
- enum_values_inconsistent_with_ar_enum: Simple::EnumValuesInconsistentWithArEnum,
13
- enum_values_inconsistent_with_inclusion: Simple::EnumValuesInconsistentWithInclusion,
14
- has_one_missing_unique_index: Simple::HasOneMissingUniqueIndex,
15
- implicit_order_column_missing: Simple::ImplicitOrderColumnMissing,
16
- inconsistent_enum_type: Simple::InconsistentEnumType,
17
- inconsistent_types: Simple::InconsistentTypes,
18
- length_validator_greater_limit: Simple::LengthValidatorGreaterLimit,
19
- length_validator_lower_limit: Simple::LengthValidatorLowerLimit,
20
- length_validator_missing: Simple::LengthValidatorMissing,
21
- missing_association_class: Simple::MissingAssociationClass,
22
- missing_foreign_key: Simple::MissingForeignKey,
23
- missing_foreign_key_cascade: Simple::MissingForeignKeyCascade,
24
- missing_table: Simple::MissingTable,
25
- missing_unique_index: Simple::MissingUniqueIndex,
26
- missing_uniqueness_validation: Simple::MissingUniquenessValidation,
27
- null_constraint_association_misses_validator: Simple::NullConstraintAssociationMissesValidator,
28
- null_constraint_misses_validator: Simple::NullConstraintMissesValidator,
29
- null_constraint_missing: Simple::NullConstraintMissing,
30
- possible_null: Simple::PossibleNull,
31
- redundant_case_insensitive_option: Simple::RedundantCaseInsensitiveOption,
32
- redundant_index: Simple::RedundantIndex,
33
- redundant_unique_index: Simple::RedundantUniqueIndex,
34
- small_primary_key: Simple::SmallPrimaryKey,
35
- three_state_boolean: Simple::ThreeStateBoolean
36
- }.freeze
37
-
38
8
  def write
39
9
  results.select(&method(:write?))
40
10
  .map(&method(:writer))
@@ -58,7 +28,12 @@ module DatabaseConsistency
58
28
  end
59
29
 
60
30
  def writer(report)
61
- klass = SLUG_TO_WRITER[report.error_slug] || Simple::DefaultMessage
31
+ klass = begin
32
+ "DatabaseConsistency::Writers::Simple::#{report.error_slug.to_s.classify}".constantize
33
+ rescue NameError
34
+ Simple::DefaultMessage
35
+ end
36
+
62
37
  klass.new(report, config: config)
63
38
  end
64
39
  end
@@ -1,6 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_record'
4
+ require 'active_support/inflector'
5
+
6
+ ActiveSupport::Inflector.inflections do |inflect|
7
+ inflect.irregular 'index', 'indexes'
8
+ end
4
9
 
5
10
  require 'database_consistency/version'
6
11
  require 'database_consistency/helper'
@@ -60,6 +65,15 @@ require 'database_consistency/databases/factory'
60
65
  require 'database_consistency/databases/types/base'
61
66
  require 'database_consistency/databases/types/sqlite'
62
67
 
68
+ require 'database_consistency/processors/base_processor'
69
+ require 'database_consistency/processors/enums_processor'
70
+ require 'database_consistency/processors/associations_processor'
71
+ require 'database_consistency/processors/validators_processor'
72
+ require 'database_consistency/processors/columns_processor'
73
+ require 'database_consistency/processors/validators_fractions_processor'
74
+ require 'database_consistency/processors/indexes_processor'
75
+ require 'database_consistency/processors/models_processor'
76
+
63
77
  require 'database_consistency/checkers/base_checker'
64
78
 
65
79
  require 'database_consistency/checkers/enum_checkers/enum_checker'
@@ -95,15 +109,6 @@ require 'database_consistency/checkers/index_checkers/unique_index_checker'
95
109
  require 'database_consistency/checkers/index_checkers/redundant_index_checker'
96
110
  require 'database_consistency/checkers/index_checkers/redundant_unique_index_checker'
97
111
 
98
- require 'database_consistency/processors/base_processor'
99
- require 'database_consistency/processors/enums_processor'
100
- require 'database_consistency/processors/associations_processor'
101
- require 'database_consistency/processors/validators_processor'
102
- require 'database_consistency/processors/columns_processor'
103
- require 'database_consistency/processors/validators_fractions_processor'
104
- require 'database_consistency/processors/indexes_processor'
105
- require 'database_consistency/processors/models_processor'
106
-
107
112
  # The root module
108
113
  module DatabaseConsistency
109
114
  class << self
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.27
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeniy Demin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-24 00:00:00.000000000 Z
11
+ date: 2024-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord