database_consistency 2.0.4 → 2.0.6
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/association_checker.rb +4 -0
- data/lib/database_consistency/checkers/association_checkers/foreign_key_checker.rb +7 -2
- data/lib/database_consistency/checkers/base_checker.rb +1 -2
- data/lib/database_consistency/checkers/column_checkers/column_checker.rb +4 -0
- data/lib/database_consistency/checkers/enum_checkers/enum_checker.rb +4 -0
- data/lib/database_consistency/checkers/index_checkers/index_checker.rb +4 -0
- data/lib/database_consistency/checkers/model_checkers/model_checker.rb +4 -0
- data/lib/database_consistency/checkers/validator_checkers/validator_checker.rb +4 -0
- data/lib/database_consistency/checkers/validators_fraction_checkers/validators_fraction_checker.rb +4 -0
- data/lib/database_consistency/configuration.rb +8 -7
- data/lib/database_consistency/debug_context.rb +0 -1
- data/lib/database_consistency/helper.rb +4 -0
- data/lib/database_consistency/version.rb +1 -1
- data/lib/database_consistency.rb +0 -5
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6008fb2151b236c23471bb000bafc433347f3e688f93ccfab02dd1c33008f21
|
4
|
+
data.tar.gz: dbf2cf3bedae1a4e7595be03a0c85c960d3fca7a15af902aac5d2b32d4ff5a1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fcf39eab6149c46d1971fdbbf577494eaaf4388518ec1863672f1043f6c3fb0fe55580384752db85900f9ff94a6e6e1016d065a363c9d6e1d4dfe60014101e1
|
7
|
+
data.tar.gz: 035e0959fb1adadf7027279b52a302ade943c7c6cfd122742085154f6b867247b8bbbdc7beb9398b3ad559d0c568fadc9333d0cc7aa74c819100e7434bd8f75b
|
@@ -42,8 +42,13 @@ module DatabaseConsistency
|
|
42
42
|
# | ----------- | ------ |
|
43
43
|
# | persisted | ok |
|
44
44
|
# | missing | fail |
|
45
|
-
def check
|
46
|
-
|
45
|
+
def check # rubocop:disable Metrics/AbcSize
|
46
|
+
fk_exist = model.connection.foreign_keys(model.table_name).any? do |fk|
|
47
|
+
(Helper.extract_columns(association.foreign_key.to_s) - Array.wrap(fk.column)).empty? &&
|
48
|
+
fk.to_table == association.klass.table_name
|
49
|
+
end
|
50
|
+
|
51
|
+
if fk_exist
|
47
52
|
report_template(:ok)
|
48
53
|
else
|
49
54
|
report_template(:fail, error_slug: :missing_foreign_key)
|
@@ -16,8 +16,7 @@ module DatabaseConsistency
|
|
16
16
|
|
17
17
|
return if subclass.superclass.name == 'DatabaseConsistency::Checkers::BaseChecker'
|
18
18
|
|
19
|
-
|
20
|
-
processor = "DatabaseConsistency::Processors::#{processor_prefix}Processor".constantize
|
19
|
+
processor = subclass.processor
|
21
20
|
processor.checkers << subclass
|
22
21
|
end
|
23
22
|
|
data/lib/database_consistency/checkers/validators_fraction_checkers/validators_fraction_checker.rb
CHANGED
@@ -6,6 +6,10 @@ module DatabaseConsistency
|
|
6
6
|
class ValidatorsFractionChecker < BaseChecker
|
7
7
|
attr_reader :model, :attribute, :validators
|
8
8
|
|
9
|
+
def self.processor
|
10
|
+
Processors::ValidatorsFractionsProcessor
|
11
|
+
end
|
12
|
+
|
9
13
|
def initialize(model, attribute, validators)
|
10
14
|
super()
|
11
15
|
@model = model
|
@@ -8,15 +8,16 @@ module DatabaseConsistency
|
|
8
8
|
DEFAULT_PATH = '.database_consistency.yml'
|
9
9
|
|
10
10
|
def initialize(file_paths = DEFAULT_PATH)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
extract_configurations(existing_paths)
|
11
|
+
existing_paths = existing_configurations(file_paths)
|
12
|
+
|
13
|
+
if existing_paths.any?
|
14
|
+
puts "Loaded configurations: #{existing_paths.join(', ')}"
|
15
|
+
else
|
16
|
+
puts 'No configurations were provided'
|
18
17
|
end
|
19
18
|
|
19
|
+
@configuration = extract_configurations(existing_paths)
|
20
|
+
|
20
21
|
load_custom_checkers
|
21
22
|
end
|
22
23
|
|
@@ -112,6 +112,10 @@ module DatabaseConsistency
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
+
def extract_columns(str)
|
116
|
+
str.scan(/(\w+)/).flatten
|
117
|
+
end
|
118
|
+
|
115
119
|
def foreign_key_or_attribute(model, attribute)
|
116
120
|
model._reflect_on_association(attribute)&.foreign_key || attribute
|
117
121
|
end
|
data/lib/database_consistency.rb
CHANGED
@@ -1,11 +1,6 @@
|
|
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
|
9
4
|
|
10
5
|
require 'database_consistency/version'
|
11
6
|
require 'database_consistency/helper'
|
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: 2.0.
|
4
|
+
version: 2.0.6
|
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: 2025-
|
11
|
+
date: 2025-09-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,10 +273,9 @@ 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.4.1
|
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
|
-
...
|