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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59cc85177c9762e632bfe92d3b04cef26491e7623494559d254d5d6e26367c7a
|
4
|
+
data.tar.gz: 6ad7b6ecdd81506ddbc9f5b9178a152e5637ee5a3d96a073169007fbfbd05c8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62182073f827085734ca241142f1f5eb38164d7fbb200da56a0d4f666193455832c6eac1e87fe1b0ca69fd51950a4bd539a924f92c7c7b276638327226abe961
|
7
|
+
data.tar.gz: f719209610b87c17fcc682cfda1e57f6a5754098ddbea47e2824a163b95319aec4f4dac8a02bb2ff8c375dd48ad2e45151536a2edffe2e75c8da9beb15af3fd2
|
@@ -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 ||= ([
|
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
|
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.
|
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-
|
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.
|
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
|