unique_validation_inspector 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 657d8b8f263904dcf7ddc6bd423c28de265fe5e0
|
4
|
+
data.tar.gz: f1a2ddead37ddd750d97ed91c7831937263917f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1b2d0d481f3d1d0e156ee6de7a913363a98c76e05a4c7fc93078471ad25a3da2d651fcd3a0c73e838d0dd58916e14119b907a8578df96d2d576ae80d347fdb5
|
7
|
+
data.tar.gz: 72ce6e1f88ffeef1d9ea43d68df50226e7885c0c7d83461d0acc0da75f5912d4c60dc1c7793d2ff64a8614b9a4980aff1c612f93fdb876c72babfc134d60b3d8
|
@@ -6,19 +6,44 @@ task :inspect_unique_validations => :environment do
|
|
6
6
|
defined_unique_validations = inspector.defined_unique_validations
|
7
7
|
|
8
8
|
puts
|
9
|
-
puts "You have the following unique validations:"
|
10
9
|
|
11
|
-
defined_unique_validations.
|
12
|
-
|
10
|
+
if defined_unique_validations.any?
|
11
|
+
puts "You have the following unique validations:"
|
12
|
+
|
13
|
+
have_at_least_one_issue = false
|
14
|
+
|
15
|
+
defined_unique_validations.each do |item|
|
16
|
+
model = item[:model]
|
17
|
+
puts
|
18
|
+
puts "Model '#{model.name}':"
|
19
|
+
item[:validators].each do |validation|
|
20
|
+
scope = validation.options[:scope]
|
21
|
+
attributes = validation.attributes
|
22
|
+
index_exists = inspector.defined_unique_indexes(model.table_name, attributes, scope)
|
23
|
+
have_at_least_one_issue = true unless index_exists
|
24
|
+
message = "#{attributes}"
|
25
|
+
message += " (scope '#{scope}')" if scope
|
26
|
+
message += ". Index exists: #{index_exists}."
|
27
|
+
puts message
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
13
31
|
puts
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
puts "
|
32
|
+
|
33
|
+
if have_at_least_one_issue
|
34
|
+
puts "Consider use one of the following solutions to resolve above issues:\n"
|
35
|
+
puts "#1. Add proper DB index.\n"
|
36
|
+
puts "#2. Move unique validation to DB level.\n"
|
37
|
+
puts "More info in the article https://medium.com/@igorkhomenko/rails-make-sure-you-have-proper-db-indexes-for-your-models-unique-validations-ffd0364df26f"
|
38
|
+
else
|
39
|
+
puts "Congrats! You do not have any issues with your unique validations - all the indexes are fine!\n"
|
40
|
+
puts "Quick recommendation: you may consider move unique validations to DB level.\n"
|
41
|
+
puts "More info in the article https://medium.com/@igorkhomenko/rails-make-sure-you-have-proper-db-indexes-for-your-models-unique-validations-ffd0364df26f"
|
20
42
|
end
|
43
|
+
else
|
44
|
+
puts "You do not have any unique validations in your project so you are fine."
|
21
45
|
end
|
46
|
+
|
22
47
|
puts
|
23
48
|
|
24
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unique_validation_inspector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Khomenko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|