database_consistency 1.6.0 → 1.7.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: de35bff4be332ceca4a982d5cde674db49db44a53d3fce22e177cc561cfe6253
4
- data.tar.gz: 9f519c9b7aef026da3033790b47690c513871b725b5271e77afa55f29014480f
3
+ metadata.gz: 8049cc73c646f8be58c7f7b3491a0dc02f55f3c75eac32803b850f8c272d11fa
4
+ data.tar.gz: fdf3df62bb8df2995889a5c717e22fb437260ebfd77d0bd80bdb5d7b9f90494a
5
5
  SHA512:
6
- metadata.gz: bdbd9750c5a9f8470a0c73fbae78a50193b423367b934f244fe0132e0dc9af29011cf55b8ef67a6dbe22f7fee3b4bbc012069dac2ae329ccad6f43452f83c80d
7
- data.tar.gz: 133abb119e8a80c25b6c4fe0936273dd328adbd6df7bc290ea16f97e695b6468f99a0b9c10bea0420dbc1788de88c73948ea429981b30812002a7b103b2f9ddf
6
+ metadata.gz: e05dcd8d5f1dc062e482a7028f2e10c3232377f1fb7c44609ea41fffb9f14fb3a331db407a693fe5ffe1c0f69d0105e3c39b65166210a6ded5365a1e239ebb50
7
+ data.tar.gz: 4dba6ecf15c4f3b6ae3553c28873e23ef77b930a4275124f14b9dfae8b84cb8bfee53033fc4f84a573064c1ebd9b702bb32dddf0fa66c8838e373bb0a372f8ee
@@ -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? && 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
@@ -13,6 +13,10 @@ module DatabaseConsistency
13
13
  end
14
14
  end
15
15
 
16
+ def postgresql?
17
+ adapter == 'postgresql'
18
+ end
19
+
16
20
  def connection_config(klass)
17
21
  if klass.respond_to?(:connection_config)
18
22
  klass.connection_config
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DatabaseConsistency
4
- VERSION = '1.6.0'
4
+ VERSION = '1.7.0'
5
5
  end
@@ -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
@@ -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.6.0
4
+ version: 1.7.0
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-03 00:00:00.000000000 Z
11
+ date: 2022-12-05 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