database_consistency 1.6.0 → 1.7.1
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/column_checkers/enum_value_checker.rb +1 -5
- data/lib/database_consistency/checkers/validator_checkers/case_sensitive_unique_validation_checker.rb +34 -0
- data/lib/database_consistency/helper.rb +4 -0
- data/lib/database_consistency/processors/validators_processor.rb +2 -1
- data/lib/database_consistency/version.rb +1 -1
- data/lib/database_consistency/writers/simple/redundant_case_insensitive_option.rb +22 -0
- data/lib/database_consistency/writers/simple_writer.rb +2 -1
- data/lib/database_consistency.rb +2 -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: 66ce7a52d5ba8e97db7d362d92c6a40df067f6fbab3945aa0f97ec80017ed265
|
4
|
+
data.tar.gz: 52b9314bb94e5664cfe791535596ad1de1055e378a37dd0b9f909d595c633a51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c72b8c701d2e90e4fd981c27a63b6a1369f10af8c51021006cb78bf19d92f24d280c36cbb4654db8929c3f26069769fa8fd23145c444a2fe565dacadadbed7cc
|
7
|
+
data.tar.gz: 763b0564fe4d78619e5d0ba0245837dbf74634f9480237b1b68f47f04ae5be3dfa2c943aa9da6257ec7b2b6159e1dfef6772a12ca656a3d7de45d916f4c6b10c
|
@@ -24,11 +24,7 @@ module DatabaseConsistency
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def preconditions
|
27
|
-
postgresql? && column.type == :enum && (enum || inclusion_validator)
|
28
|
-
end
|
29
|
-
|
30
|
-
def postgresql?
|
31
|
-
Helper.adapter == 'postgresql'
|
27
|
+
Helper.postgresql? && ActiveRecord::VERSION::MAJOR >= 7 && column.type == :enum && (enum || inclusion_validator)
|
32
28
|
end
|
33
29
|
|
34
30
|
def check
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
module Checkers
|
5
|
+
# This class checks if uniqueness validator has unique index in the database
|
6
|
+
class CaseSensitiveUniqueValidationChecker < ValidatorChecker
|
7
|
+
private
|
8
|
+
|
9
|
+
def preconditions
|
10
|
+
validator.kind == :uniqueness && Helper.postgresql? && citext?
|
11
|
+
end
|
12
|
+
|
13
|
+
def check
|
14
|
+
if validator.options[:case_sensitive].nil? || validator.options[:case_sensitive]
|
15
|
+
report_template(:ok)
|
16
|
+
else
|
17
|
+
report_template(:fail, error_slug: :redundant_case_insensitive_option)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def citext?
|
22
|
+
field_name = Helper.foreign_key_or_attribute(model, attribute)
|
23
|
+
|
24
|
+
field = model.columns.find { |column| column.name.to_s == field_name.to_s }
|
25
|
+
|
26
|
+
field&.type == :citext
|
27
|
+
end
|
28
|
+
|
29
|
+
def sorted_uniqueness_validator_columns
|
30
|
+
@sorted_uniqueness_validator_columns ||= Helper.sorted_uniqueness_validator_columns(attribute, validator, model)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -5,7 +5,8 @@ module DatabaseConsistency
|
|
5
5
|
# The class to process validators
|
6
6
|
class ValidatorsProcessor < BaseProcessor
|
7
7
|
CHECKERS = [
|
8
|
-
Checkers::MissingUniqueIndexChecker
|
8
|
+
Checkers::MissingUniqueIndexChecker,
|
9
|
+
Checkers::CaseSensitiveUniqueValidationChecker
|
9
10
|
].freeze
|
10
11
|
|
11
12
|
private
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
module Writers
|
5
|
+
module Simple
|
6
|
+
class RedundantCaseInsensitiveOption < Base # :nodoc:
|
7
|
+
private
|
8
|
+
|
9
|
+
def template
|
10
|
+
"has case insensitive type and doesn't require case_sensitive: false option"
|
11
|
+
end
|
12
|
+
|
13
|
+
def unique_attributes
|
14
|
+
{
|
15
|
+
table_or_model_name: report.table_or_model_name,
|
16
|
+
column_or_attribute_name: report.column_or_attribute_name
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -27,7 +27,8 @@ module DatabaseConsistency
|
|
27
27
|
inconsistent_enum_type: Simple::InconsistentEnumType,
|
28
28
|
missing_foreign_key_cascade: Simple::MissingForeignKeyCascade,
|
29
29
|
enum_values_inconsistent_with_ar_enum: Simple::EnumValuesInconsistentWithArEnum,
|
30
|
-
enum_values_inconsistent_with_inclusion: Simple::EnumValuesInconsistentWithInclusion
|
30
|
+
enum_values_inconsistent_with_inclusion: Simple::EnumValuesInconsistentWithInclusion,
|
31
|
+
redundant_case_insensitive_option: Simple::RedundantCaseInsensitiveOption
|
31
32
|
}.freeze
|
32
33
|
|
33
34
|
def write
|
data/lib/database_consistency.rb
CHANGED
@@ -37,6 +37,7 @@ require 'database_consistency/writers/simple/small_primary_key'
|
|
37
37
|
require 'database_consistency/writers/simple/inconsistent_enum_type'
|
38
38
|
require 'database_consistency/writers/simple/enum_values_inconsistent_with_ar_enum'
|
39
39
|
require 'database_consistency/writers/simple/enum_values_inconsistent_with_inclusion'
|
40
|
+
require 'database_consistency/writers/simple/redundant_case_insensitive_option'
|
40
41
|
require 'database_consistency/writers/simple_writer'
|
41
42
|
|
42
43
|
require 'database_consistency/writers/autofix/helpers/migration'
|
@@ -73,6 +74,7 @@ require 'database_consistency/checkers/column_checkers/enum_value_checker'
|
|
73
74
|
|
74
75
|
require 'database_consistency/checkers/validator_checkers/validator_checker'
|
75
76
|
require 'database_consistency/checkers/validator_checkers/missing_unique_index_checker'
|
77
|
+
require 'database_consistency/checkers/validator_checkers/case_sensitive_unique_validation_checker'
|
76
78
|
|
77
79
|
require 'database_consistency/checkers/validators_fraction_checkers/validators_fraction_checker'
|
78
80
|
require 'database_consistency/checkers/validators_fraction_checkers/column_presence_checker'
|
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.
|
4
|
+
version: 1.7.1
|
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-12-
|
11
|
+
date: 2022-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -163,6 +163,7 @@ files:
|
|
163
163
|
- lib/database_consistency/checkers/index_checkers/redundant_index_checker.rb
|
164
164
|
- lib/database_consistency/checkers/index_checkers/redundant_unique_index_checker.rb
|
165
165
|
- lib/database_consistency/checkers/index_checkers/unique_index_checker.rb
|
166
|
+
- lib/database_consistency/checkers/validator_checkers/case_sensitive_unique_validation_checker.rb
|
166
167
|
- lib/database_consistency/checkers/validator_checkers/missing_unique_index_checker.rb
|
167
168
|
- lib/database_consistency/checkers/validator_checkers/validator_checker.rb
|
168
169
|
- lib/database_consistency/checkers/validators_fraction_checkers/column_presence_checker.rb
|
@@ -223,6 +224,7 @@ files:
|
|
223
224
|
- lib/database_consistency/writers/simple/null_constraint_misses_validator.rb
|
224
225
|
- lib/database_consistency/writers/simple/null_constraint_missing.rb
|
225
226
|
- lib/database_consistency/writers/simple/possible_null.rb
|
227
|
+
- lib/database_consistency/writers/simple/redundant_case_insensitive_option.rb
|
226
228
|
- lib/database_consistency/writers/simple/redundant_index.rb
|
227
229
|
- lib/database_consistency/writers/simple/redundant_unique_index.rb
|
228
230
|
- lib/database_consistency/writers/simple/small_primary_key.rb
|