database_consistency 0.8.13 → 1.0.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: b074df0ae4a1316afdb9874c811a02189fd664e00b85220730dd0ae985a36c76
|
4
|
+
data.tar.gz: f870f9f74117a6ea1b5592e7610becc5f854c375ee4a82f9720b287ae9288462
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99e298ec2e58c3bfcc5c10a9e294891b14eee23b1a4c9ccbf3e78f5e500480baf1c3ec397d0a19f5af6e83f05dbe9a297e062358eab9699d324b6b06a1255889
|
7
|
+
data.tar.gz: 7d742b1d5985792e2fa3b3a6d5195ccb91c4b49cdbcbce800de6db29a16ef1045f4bf786b3d88e981d23b573282d4ddb821ede90951890ab45682c16b37ede7b
|
data/lib/database_consistency.rb
CHANGED
@@ -35,6 +35,7 @@ require 'database_consistency/checkers/validators_fraction_checkers/column_prese
|
|
35
35
|
|
36
36
|
require 'database_consistency/checkers/index_checkers/index_checker'
|
37
37
|
require 'database_consistency/checkers/index_checkers/unique_index_checker'
|
38
|
+
require 'database_consistency/checkers/index_checkers/redundant_index_checker'
|
38
39
|
|
39
40
|
require 'database_consistency/processors/base_processor'
|
40
41
|
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 RedundantIndexChecker < IndexChecker
|
7
|
+
# Message templates
|
8
|
+
REDUNDANT_INDEX = 'index is redundant as (%index) covers it'
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
# We skip check when:
|
13
|
+
# - index is 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_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
|
+
include_index_as_prefix?(another_index)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def include_index_as_prefix?(another_index)
|
46
|
+
another_index_columns = Helper.extract_index_columns(another_index.columns)
|
47
|
+
index_columns == another_index_columns.first(index_columns.size)
|
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,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: database_consistency
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.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: 2021-
|
11
|
+
date: 2021-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -122,7 +122,7 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '1.3'
|
125
|
-
description:
|
125
|
+
description:
|
126
126
|
email:
|
127
127
|
- lawliet.djez@gmail.com
|
128
128
|
executables:
|
@@ -141,6 +141,7 @@ files:
|
|
141
141
|
- lib/database_consistency/checkers/column_checkers/null_constraint_checker.rb
|
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
|
+
- lib/database_consistency/checkers/index_checkers/redundant_index_checker.rb
|
144
145
|
- lib/database_consistency/checkers/index_checkers/unique_index_checker.rb
|
145
146
|
- lib/database_consistency/checkers/validator_checkers/belongs_to_presence_checker.rb
|
146
147
|
- lib/database_consistency/checkers/validator_checkers/missing_unique_index_checker.rb
|
@@ -168,7 +169,7 @@ homepage: https://github.com/djezzzl/database_consistency
|
|
168
169
|
licenses:
|
169
170
|
- MIT
|
170
171
|
metadata: {}
|
171
|
-
post_install_message:
|
172
|
+
post_install_message:
|
172
173
|
rdoc_options: []
|
173
174
|
require_paths:
|
174
175
|
- lib
|
@@ -184,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
185
|
version: '0'
|
185
186
|
requirements: []
|
186
187
|
rubygems_version: 3.0.8
|
187
|
-
signing_key:
|
188
|
+
signing_key:
|
188
189
|
specification_version: 4
|
189
190
|
summary: Provide an easy way to check the consistency of the database constraints
|
190
191
|
with the application validations.
|