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 +4 -4
- data/lib/database_consistency/checkers/association_checkers/foreign_key_checker.rb +2 -1
- data/lib/database_consistency/checkers/base_checker.rb +11 -1
- data/lib/database_consistency/checkers/column_checkers/three_state_boolean_checker.rb +2 -1
- data/lib/database_consistency/checkers/validators_fraction_checkers/column_presence_checker.rb +1 -1
- data/lib/database_consistency/configuration.rb +10 -0
- data/lib/database_consistency/processors/associations_processor.rb +0 -8
- data/lib/database_consistency/processors/base_processor.rb +6 -10
- data/lib/database_consistency/processors/columns_processor.rb +0 -9
- data/lib/database_consistency/processors/enums_processor.rb +0 -4
- data/lib/database_consistency/processors/indexes_processor.rb +0 -6
- data/lib/database_consistency/processors/models_processor.rb +0 -4
- data/lib/database_consistency/processors/validators_fractions_processor.rb +0 -4
- data/lib/database_consistency/processors/validators_processor.rb +0 -5
- data/lib/database_consistency/version.rb +1 -1
- data/lib/database_consistency/writers/simple_writer.rb +6 -31
- data/lib/database_consistency.rb +14 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba84801df64868302240abb6b325652bc21c34086c2b4d32460bb092f55d7681
|
4
|
+
data.tar.gz: 49ba63ec3857648e90121ef8e7692fe217fcb41592b21087876628caa7888427
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f29ab6930f1317041b38879890a0195ed03d7620647a08baa5061fd82cd5b124587f0acafa9fe15b1d92747b4a8e7f05528fb4882b170cdf6feb23ed326547aa
|
7
|
+
data.tar.gz: a4e7fb560d24c41aa1dc02ad3127658ac9ab6f268be885843ca03cf24bc49e4354cec95f8d78a69ad44579eaef984a555c578e347eb98645de27248c75edfe3e
|
@@ -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.
|
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
|
data/lib/database_consistency/checkers/validators_fraction_checkers/column_presence_checker.rb
CHANGED
@@ -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
|
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,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,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>]
|
@@ -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 =
|
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
|
data/lib/database_consistency.rb
CHANGED
@@ -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:
|
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-
|
11
|
+
date: 2024-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|