database_consistency 2.0.5 → 2.0.7
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 +7 -2
- data/lib/database_consistency/checkers/index_checkers/redundant_index_checker.rb +2 -2
- data/lib/database_consistency/helper.rb +9 -0
- data/lib/database_consistency/version.rb +1 -1
- 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: 8aa53651a6fab582987c49a3667bb618bf97f9f8cc48418a6c7fc0e22457104c
|
|
4
|
+
data.tar.gz: 7d23f15f92702e6d4bea909a5b267265da71f331653dae27d987441596806e9d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fe01102c680e3439282bc24e7e5d98ae2ff8a14eac30339500b912902b70f9c2069d284753cd9db768d9cb1ed0c91d31332af92082ca87f01be104e10f0cc226
|
|
7
|
+
data.tar.gz: 7dabf536ab2825e6eae778dc97edca36c56eba676647856e05a3c287d28248287cf7f6918f563f6e1022712822719037525faf029de4a89d551439a95c6df225
|
|
@@ -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,7 +16,7 @@ module DatabaseConsistency
|
|
|
16
16
|
# We skip check when:
|
|
17
17
|
# - index is unique
|
|
18
18
|
def preconditions
|
|
19
|
-
!index.unique
|
|
19
|
+
!index.unique && Helper.btree_index?(index)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
# Table of possible statuses
|
|
@@ -48,7 +48,7 @@ module DatabaseConsistency
|
|
|
48
48
|
def covered_by_index
|
|
49
49
|
@covered_by_index ||=
|
|
50
50
|
model.connection.indexes(model.table_name).find do |another_index|
|
|
51
|
-
next if index.name == another_index.name
|
|
51
|
+
next if index.name == another_index.name || !Helper.btree_index?(another_index)
|
|
52
52
|
|
|
53
53
|
clause_equals?(another_index) && include_index_as_prefix?(another_index)
|
|
54
54
|
end
|
|
@@ -112,6 +112,15 @@ module DatabaseConsistency
|
|
|
112
112
|
end
|
|
113
113
|
end
|
|
114
114
|
|
|
115
|
+
def btree_index?(index)
|
|
116
|
+
(index.type.nil? || index.type.to_s == 'btree') &&
|
|
117
|
+
(index.using.nil? || index.using.to_s == 'btree')
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def extract_columns(str)
|
|
121
|
+
str.scan(/(\w+)/).flatten
|
|
122
|
+
end
|
|
123
|
+
|
|
115
124
|
def foreign_key_or_attribute(model, attribute)
|
|
116
125
|
model._reflect_on_association(attribute)&.foreign_key || attribute
|
|
117
126
|
end
|
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.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Evgeniy Demin
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-11-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|