database_consistency 0.6.5 → 0.6.6

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: 6474192e36ae6bcd25dc149e1294ff9c791d2716e2dab3d94191b8c47dd81aef
4
- data.tar.gz: d523c7bf119274212cb9da1ead5c04814e970157529e06f03c27b2d7ad2463da
3
+ metadata.gz: 59cc85177c9762e632bfe92d3b04cef26491e7623494559d254d5d6e26367c7a
4
+ data.tar.gz: 6ad7b6ecdd81506ddbc9f5b9178a152e5637ee5a3d96a073169007fbfbd05c8a
5
5
  SHA512:
6
- metadata.gz: 9e90c491f1f0ced39b6ce7b66079586f6f42b0405214392f110ec04d6ee41fbcdd01031ac88fc3dfe662669ae3640957941013981c5965a97b6032d36271f105
7
- data.tar.gz: f405932ab3023150e3353b5bfe08e6bb56c79b3af0d55a45c2f449c9dee45d1d44ac255e83fecac8b70d8ff967a1b8fe9fe23016446c53b84a27a12bcb666024
6
+ metadata.gz: 62182073f827085734ca241142f1f5eb38164d7fbb200da56a0d4f666193455832c6eac1e87fe1b0ca69fd51950a4bd539a924f92c7c7b276638327226abe961
7
+ data.tar.gz: f719209610b87c17fcc682cfda1e57f6a5754098ddbea47e2824a163b95319aec4f4dac8a02bb2ff8c375dd48ad2e45151536a2edffe2e75c8da9beb15af3fd2
@@ -21,8 +21,8 @@ module DatabaseConsistency
21
21
  return unless preconditions
22
22
 
23
23
  @report ||= check
24
- rescue StandardError => error
25
- RescueError.call(error)
24
+ rescue StandardError => e
25
+ RescueError.call(e)
26
26
  end
27
27
 
28
28
  # @return [Hash, nil]
@@ -33,17 +33,36 @@ module DatabaseConsistency
33
33
 
34
34
  def unique_index
35
35
  @unique_index ||= model.connection.indexes(model.table_name).find do |index|
36
- index.unique && index.columns.sort == sorted_index_columns
36
+ index.unique && extract_index_columns(index.columns).sort == sorted_index_columns
37
37
  end
38
38
  end
39
39
 
40
+ # @return [Array<String>]
41
+ def extract_index_columns(index_columns)
42
+ return index_columns unless index_columns.is_a?(String)
43
+
44
+ index_columns.split(',')
45
+ .map(&:strip)
46
+ .map { |str| str.gsub(/lower\(/i, 'lower(') }
47
+ .map { |str| str.gsub(/\(([^)]+)\)::\w+/, '\1') }
48
+ end
49
+
40
50
  def index_columns
41
- @index_columns ||= ([attribute] + Array.wrap(validator.options[:scope])).map(&:to_s)
51
+ @index_columns ||= ([wrapped_attribute_name] + Array.wrap(validator.options[:scope])).map(&:to_s)
42
52
  end
43
53
 
44
54
  def sorted_index_columns
45
55
  @sorted_index_columns ||= index_columns.sort
46
56
  end
57
+
58
+ # @return [String]
59
+ def wrapped_attribute_name
60
+ if validator.options[:case_sensitive].nil? || validator.options[:case_sensitive]
61
+ attribute
62
+ else
63
+ "lower(#{attribute})"
64
+ end
65
+ end
47
66
  end
48
67
  end
49
68
  end
@@ -12,10 +12,12 @@ module DatabaseConsistency
12
12
  @validator = validator
13
13
  end
14
14
 
15
+ # @return [String]
15
16
  def column_or_attribute_name
16
17
  @column_or_attribute_name ||= attribute.to_s
17
18
  end
18
19
 
20
+ # @return [String]
19
21
  def table_or_model_name
20
22
  @table_or_model_name ||= model.name.to_s
21
23
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DatabaseConsistency
4
- VERSION = '0.6.5'
4
+ VERSION = '0.6.6'
5
5
  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.6.5
4
+ version: 0.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeniy Demin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-30 00:00:00.000000000 Z
11
+ date: 2019-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -177,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
177
  version: '0'
178
178
  requirements: []
179
179
  rubyforge_project:
180
- rubygems_version: 2.7.8
180
+ rubygems_version: 2.7.9
181
181
  signing_key:
182
182
  specification_version: 4
183
183
  summary: Provide an easy way to check the consistency of the database constraints