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: 46a8e208afca114d0cf07b514a54fb91bc0f9d02
4
- data.tar.gz: b34defca8e956fd5a338cc38c8bd5684243e5f30
3
+ metadata.gz: 657d8b8f263904dcf7ddc6bd423c28de265fe5e0
4
+ data.tar.gz: f1a2ddead37ddd750d97ed91c7831937263917f6
5
5
  SHA512:
6
- metadata.gz: ed84da62e136620b773e90f2658beb41b697d6cd899030d86d282a41b3dd58e3f516f3e1540b901281f947604122a194de4715cc72270c46189476c10400c392
7
- data.tar.gz: a8c57932bc049e372ed622320c90c5fdd02f1a4c870eb56cede6513c394fadbf85bb965501de5d7da12f49c525c9f1def18e0c7bceff85f21d3c66b9375993a3
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.each do |item|
12
- model = item[:model]
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
- puts "Model '#{model.name}':"
15
- item[:validators].each do |validation|
16
- scope = validation.options[:scope]
17
- attributes = validation.attributes
18
- index_exists = inspector.defined_unique_indexes(model.table_name, attributes, scope)
19
- puts "#{attributes} (scope '#{scope}'). Index exists: #{index_exists}"
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
@@ -1,3 +1,3 @@
1
1
  module UniqueValidationInspector
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  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.1.3
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-08-23 00:00:00.000000000 Z
11
+ date: 2017-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails