database_consistency 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f37408420931f459ea476d095f441e40256ea2279e07c21ad9d477c0781d5944
|
4
|
+
data.tar.gz: b054877a7819333fab57dbe22786456d4a0328b462f9808561e470290b3ae6e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2e7a18dabde150f3f1f2ee144b6076e2c0fb944c9c128851379e86007f0aed056f1fb550cc19319b777767ffc165534939a680e248213473032054dfa8e2924
|
7
|
+
data.tar.gz: f047ff2a3e5e41137a93f5c64e4a0288e74b0d687670e7eabe5b3656a675abf87df75586fd5a0988f25f26f993d20542addfd2d84b430dac7dd30025f2016415
|
data/lib/database_consistency.rb
CHANGED
@@ -36,6 +36,7 @@ require 'database_consistency/checkers/validators_fraction_checkers/column_prese
|
|
36
36
|
require 'database_consistency/checkers/index_checkers/index_checker'
|
37
37
|
require 'database_consistency/checkers/index_checkers/unique_index_checker'
|
38
38
|
require 'database_consistency/checkers/index_checkers/redundant_index_checker'
|
39
|
+
require 'database_consistency/checkers/index_checkers/redundant_unique_index_checker'
|
39
40
|
|
40
41
|
require 'database_consistency/processors/base_processor'
|
41
42
|
require 'database_consistency/processors/associations_processor'
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
module Checkers
|
5
|
+
# This class checks redundant database indexes
|
6
|
+
class RedundantUniqueIndexChecker < IndexChecker
|
7
|
+
# Message templates
|
8
|
+
REDUNDANT_UNIQUE_INDEX = 'index uniqueness is redundant as (%index) covers it'
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
# We skip check when:
|
13
|
+
# - index is not unique
|
14
|
+
def preconditions
|
15
|
+
index.unique
|
16
|
+
end
|
17
|
+
|
18
|
+
# Table of possible statuses
|
19
|
+
# | validation | status |
|
20
|
+
# | ---------- | ------ |
|
21
|
+
# | provided | ok |
|
22
|
+
# | redundant | fail |
|
23
|
+
#
|
24
|
+
def check
|
25
|
+
if covered_by_index
|
26
|
+
report_template(:fail, render_message)
|
27
|
+
else
|
28
|
+
report_template(:ok)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def render_message
|
33
|
+
REDUNDANT_UNIQUE_INDEX.sub('%index', covered_by_index.name)
|
34
|
+
end
|
35
|
+
|
36
|
+
def covered_by_index
|
37
|
+
@covered_by_index ||=
|
38
|
+
model.connection.indexes(model.table_name).find do |another_index|
|
39
|
+
next if index.name == another_index.name
|
40
|
+
|
41
|
+
another_index.unique && contain_index?(another_index)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def contain_index?(another_index)
|
46
|
+
another_index_columns = Helper.extract_index_columns(another_index.columns)
|
47
|
+
index_columns & another_index_columns == another_index_columns
|
48
|
+
end
|
49
|
+
|
50
|
+
def index_columns
|
51
|
+
@index_columns ||= Helper.extract_index_columns(index.columns)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: database_consistency
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evgeniy Demin
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- lib/database_consistency/checkers/column_checkers/primary_key_type_checker.rb
|
143
143
|
- lib/database_consistency/checkers/index_checkers/index_checker.rb
|
144
144
|
- lib/database_consistency/checkers/index_checkers/redundant_index_checker.rb
|
145
|
+
- lib/database_consistency/checkers/index_checkers/redundant_unique_index_checker.rb
|
145
146
|
- lib/database_consistency/checkers/index_checkers/unique_index_checker.rb
|
146
147
|
- lib/database_consistency/checkers/validator_checkers/belongs_to_presence_checker.rb
|
147
148
|
- lib/database_consistency/checkers/validator_checkers/missing_unique_index_checker.rb
|