database_consistency 1.3.2 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/database_consistency/checkers/index_checkers/redundant_index_checker.rb +7 -5
- data/lib/database_consistency/version.rb +1 -1
- data/lib/database_consistency/writers/autofix/redundant_index.rb +19 -0
- data/lib/database_consistency/writers/autofix/templates/redundant_index.tt +5 -0
- data/lib/database_consistency/writers/autofix_writer.rb +2 -1
- data/lib/database_consistency/writers/simple_writer.rb +1 -1
- data/lib/database_consistency.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 857156332ffa36d32216953b8bd1f798ae27dcb2037e873c93d08fa55a01bd47
|
4
|
+
data.tar.gz: f1aa19a34377de90e606b1e8272d9444992e44f6487c0ac28d913298d5ef6df9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 635ac9cfa1426f77ec59647e7282887fcfc81ec2db8217a545f791383bc1e3538f8f2e5bcb55c1aedee194b27287063a0ee330ffafe0068a7c219f2350a421b9
|
7
|
+
data.tar.gz: f72cf3ef8ac71296984002d798b895740fc15ec91e582503fde012d8b58986956e36bd41bfae5453abb374da27a20f92bbcf96fbfe2abdddf3fe8f2569be3f48
|
@@ -5,15 +5,16 @@ module DatabaseConsistency
|
|
5
5
|
# This class checks redundant database indexes
|
6
6
|
class RedundantIndexChecker < IndexChecker
|
7
7
|
class Report < DatabaseConsistency::Report # :nodoc:
|
8
|
-
attr_reader :index_name
|
8
|
+
attr_reader :covered_index_name, :index_name
|
9
9
|
|
10
|
-
def initialize(index_name:, **args)
|
10
|
+
def initialize(covered_index_name:, index_name:, **args)
|
11
11
|
super(**args)
|
12
|
+
@covered_index_name = covered_index_name
|
12
13
|
@index_name = index_name
|
13
14
|
end
|
14
15
|
|
15
16
|
def attributes
|
16
|
-
super.merge(index_name: index_name)
|
17
|
+
super.merge(covered_index_name: covered_index_name, index_name: index_name)
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
@@ -31,13 +32,14 @@ module DatabaseConsistency
|
|
31
32
|
# | provided | ok |
|
32
33
|
# | redundant | fail |
|
33
34
|
#
|
34
|
-
def check
|
35
|
+
def check # rubocop:disable Metrics/MethodLength
|
35
36
|
if covered_by_index
|
36
37
|
Report.new(
|
37
38
|
status: :fail,
|
38
39
|
error_slug: :redundant_index,
|
39
40
|
error_message: nil,
|
40
|
-
|
41
|
+
covered_index_name: covered_by_index.name,
|
42
|
+
index_name: index.name,
|
41
43
|
**report_attributes
|
42
44
|
)
|
43
45
|
else
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
module Writers
|
5
|
+
module Autofix
|
6
|
+
class RedundantIndex < MigrationBase # :nodoc:
|
7
|
+
private
|
8
|
+
|
9
|
+
def migration_name
|
10
|
+
"remove_#{report.index_name}_index"
|
11
|
+
end
|
12
|
+
|
13
|
+
def template_path
|
14
|
+
File.join(__dir__, 'templates', 'redundant_index.tt')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -8,7 +8,8 @@ module DatabaseConsistency
|
|
8
8
|
SLUG_TO_GENERATOR = {
|
9
9
|
missing_foreign_key: Autofix::MissingForeignKey,
|
10
10
|
null_constraint_missing: Autofix::NullConstraintMissing,
|
11
|
-
association_missing_null_constraint: Autofix::NullConstraintMissing
|
11
|
+
association_missing_null_constraint: Autofix::NullConstraintMissing,
|
12
|
+
redundant_index: Autofix::RedundantIndex
|
12
13
|
}.freeze
|
13
14
|
|
14
15
|
def write
|
@@ -29,7 +29,7 @@ module DatabaseConsistency
|
|
29
29
|
null_constraint_association_misses_validator: 'column is required in the database but do not have presence validator for association %<association_name>s', # rubocop:disable Layout/LineLength
|
30
30
|
null_constraint_misses_validator: 'column is required in the database but do not have presence validator',
|
31
31
|
small_primary_key: 'column has int/serial type but recommended to have bigint/bigserial/uuid',
|
32
|
-
redundant_index: 'index is redundant as %<
|
32
|
+
redundant_index: 'index is redundant as %<covered_index_name>s covers it',
|
33
33
|
redundant_unique_index: 'index uniqueness is redundant as %<index_name>s covers it',
|
34
34
|
missing_uniqueness_validation: 'index is unique in the database but do not have uniqueness validator',
|
35
35
|
missing_unique_index: 'model should have proper unique index in the database',
|
data/lib/database_consistency.rb
CHANGED
@@ -19,6 +19,7 @@ require 'database_consistency/writers/autofix/helpers/migration'
|
|
19
19
|
require 'database_consistency/writers/autofix/base'
|
20
20
|
require 'database_consistency/writers/autofix/migration_base'
|
21
21
|
require 'database_consistency/writers/autofix/missing_foreign_key'
|
22
|
+
require 'database_consistency/writers/autofix/redundant_index'
|
22
23
|
require 'database_consistency/writers/autofix/null_constraint_missing'
|
23
24
|
require 'database_consistency/writers/autofix_writer'
|
24
25
|
|
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: 1.3.
|
4
|
+
version: 1.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evgeniy Demin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -184,8 +184,10 @@ files:
|
|
184
184
|
- lib/database_consistency/writers/autofix/migration_base.rb
|
185
185
|
- lib/database_consistency/writers/autofix/missing_foreign_key.rb
|
186
186
|
- lib/database_consistency/writers/autofix/null_constraint_missing.rb
|
187
|
+
- lib/database_consistency/writers/autofix/redundant_index.rb
|
187
188
|
- lib/database_consistency/writers/autofix/templates/missing_foreign_key.tt
|
188
189
|
- lib/database_consistency/writers/autofix/templates/null_constraint_missing.tt
|
190
|
+
- lib/database_consistency/writers/autofix/templates/redundant_index.tt
|
189
191
|
- lib/database_consistency/writers/autofix_writer.rb
|
190
192
|
- lib/database_consistency/writers/base_writer.rb
|
191
193
|
- lib/database_consistency/writers/helpers/pipes.rb
|