database_consistency 1.7.26 → 2.0.0
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/base_checker.rb +11 -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/autofix/helpers/migration.rb +15 -2
- data/lib/database_consistency/writers/simple_writer.rb +6 -31
- data/lib/database_consistency.rb +14 -9
- metadata +7 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 52986b5b93512eecd5adc0b4d37f873664a2ef35eea9b42359a0870f5ecf1c6d
|
|
4
|
+
data.tar.gz: fa614ae4aa5e6f1b08fadd0d252e898745e1300aae1e5a65466727a80a41ec38
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3d7309cf8351e0a7aac9009a4aac0d299a905f09a8d2238b629c880d9810d959f59ef3f5e0d8ce09e72a30d575c60cd792821acb3b2f51c09f023588a704f5a4
|
|
7
|
+
data.tar.gz: 97cb23bf0541dbb7a95fdbbe78e836c5e9f8c52ae99fe25392c378a9b7acc22e9dd7d3020944aa97e17a1679c02a35bbacaf6067b29be5f3f65ce05bc6856c77
|
|
@@ -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
|
|
@@ -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>]
|
|
@@ -6,8 +6,6 @@ module DatabaseConsistency
|
|
|
6
6
|
module Helpers
|
|
7
7
|
module Migration # :nodoc:
|
|
8
8
|
def migration_path(name)
|
|
9
|
-
migration_context = ActiveRecord::Base.connection.migration_context
|
|
10
|
-
|
|
11
9
|
last = migration_context.migrations.last
|
|
12
10
|
version = ActiveRecord::Migration.next_migration_number(last&.version.to_i + 1)
|
|
13
11
|
|
|
@@ -24,6 +22,21 @@ module DatabaseConsistency
|
|
|
24
22
|
migration_version: ActiveRecord::Migration.current_version
|
|
25
23
|
}
|
|
26
24
|
end
|
|
25
|
+
|
|
26
|
+
def migration_context
|
|
27
|
+
if ActiveRecord::MigrationContext.instance_method(:initialize).arity == 1
|
|
28
|
+
return ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
if ActiveRecord::Base.connection.respond_to?(:schema_migration)
|
|
32
|
+
return ActiveRecord::MigrationContext.new(
|
|
33
|
+
ActiveRecord::Migrator.migrations_paths,
|
|
34
|
+
ActiveRecord::Base.connection.schema_migration
|
|
35
|
+
)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths)
|
|
39
|
+
end
|
|
27
40
|
end
|
|
28
41
|
end
|
|
29
42
|
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 =
|
|
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.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Evgeniy Demin
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-
|
|
11
|
+
date: 2024-12-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -136,7 +136,7 @@ dependencies:
|
|
|
136
136
|
- - ">"
|
|
137
137
|
- !ruby/object:Gem::Version
|
|
138
138
|
version: '1.3'
|
|
139
|
-
description:
|
|
139
|
+
description:
|
|
140
140
|
email:
|
|
141
141
|
- lawliet.djez@gmail.com
|
|
142
142
|
executables:
|
|
@@ -273,9 +273,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
273
273
|
- !ruby/object:Gem::Version
|
|
274
274
|
version: '0'
|
|
275
275
|
requirements: []
|
|
276
|
-
rubygems_version: 3.
|
|
277
|
-
signing_key:
|
|
276
|
+
rubygems_version: 3.2.33
|
|
277
|
+
signing_key:
|
|
278
278
|
specification_version: 4
|
|
279
279
|
summary: Provide an easy way to check the consistency of the database constraints
|
|
280
280
|
with the application validations.
|
|
281
281
|
test_files: []
|
|
282
|
+
...
|