unique_validation_inspector 0.2.0 → 0.3.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 +4 -4
- data/CHANGELOG.md +18 -2
- data/README.md +12 -5
- data/lib/unique_validation_inspector.rb +13 -7
- data/lib/unique_validation_inspector/version.rb +1 -1
- data/unique_validation_inspector.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58622ad0fd72e028cbfaf0120a3f5ca17608df0d
|
4
|
+
data.tar.gz: c45ece8f05bf7446d2563caf9f7cc40745a7e0ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b73b05f061e7c8f5cc7dbffae6364e3d418aedcb477b20699605651a02f6e365c57070c1bf3c393db3d7755f4f360152dc1d207768722004dcd7e0cf674520d
|
7
|
+
data.tar.gz: 596425f9a286607a3293029f128f6b198022cb1f398b3d12113ae2467fc718021711876b279cfe9202e0cb8da7974715c11bc62bd79f5fdd5d1f92dcc4f475cb
|
data/CHANGELOG.md
CHANGED
@@ -1,14 +1,30 @@
|
|
1
|
+
## 0.3.0 (February 28, 2018)
|
2
|
+
|
3
|
+
#### Features
|
4
|
+
|
5
|
+
* Now we look for unique DB indexes only ([#4](https://github.com/soulfly/unique_validation_inspector/pull/4) by [@mrdougwright](https://github.com/mrdougwright))
|
6
|
+
|
7
|
+
#### Fixes
|
8
|
+
|
9
|
+
* Issue where DB indexes for validations with scope were not properly recognized ([#4](https://github.com/soulfly/unique_validation_inspector/pull/4) by [@mrdougwright](https://github.com/mrdougwright))
|
10
|
+
|
11
|
+
## 0.2.0 (September 16, 2017)
|
12
|
+
|
13
|
+
#### Features
|
14
|
+
|
15
|
+
* Better output message format
|
16
|
+
|
1
17
|
## 0.1.3 (August 23, 2017)
|
2
18
|
|
3
19
|
#### Fixes
|
4
20
|
|
5
|
-
* No models are loaded on some apps (https://github.com/soulfly/unique_validation_inspector/pull/2)
|
21
|
+
* No models are loaded on some apps ([#2](https://github.com/soulfly/unique_validation_inspector/pull/2))
|
6
22
|
|
7
23
|
## 0.1.2 (August 14, 2017)
|
8
24
|
|
9
25
|
#### Fixes
|
10
26
|
|
11
|
-
* Task fails with abstract model with no table on db (https://github.com/soulfly/unique_validation_inspector/issues/1)
|
27
|
+
* Task fails with abstract model with no table on db ([#1](https://github.com/soulfly/unique_validation_inspector/issues/1))
|
12
28
|
|
13
29
|
## 0.1.1 (August 11, 2017)
|
14
30
|
|
data/README.md
CHANGED
@@ -12,16 +12,18 @@ For example, you have **User** model and uniqueness validation for **facebook_id
|
|
12
12
|
```sql
|
13
13
|
SELECT 1 AS one FROM `users` WHERE (`users`.`facebook_id ` = 1523123128921623) LIMIT 1
|
14
14
|
```
|
15
|
-
If you do not have DB index for **facebook_id** field then your **Model.create**, **Model.save**, **Model.update** ... operations will be slower and slower with user base grow.
|
15
|
+
If you do not have DB index for **facebook_id** field then your **Model.create**, **Model.save**, **Model.update** ... operations will be slower and slower with user base grow.
|
16
16
|
|
17
17
|
So this gem is here to notify you about it.
|
18
18
|
|
19
|
-
Read [
|
19
|
+
Read [Rails: make sure you have proper DB indexes for your model’s unique validations](https://medium.com/@igorkhomenko/rails-make-sure-you-have-proper-db-indexes-for-your-models-unique-validations-ffd0364df26f) article to understand what kind of performance issues you may have without proper indexes.
|
20
|
+
|
21
|
+
Also read [How I Reduced my DB Server Load by 80%](https://schneems.com/2017/07/18/how-i-reduced-my-db-server-load-by-80/) article.
|
20
22
|
|
21
23
|
## Supported versions
|
22
|
-
* Ruby 1.8.7, 1.9.2, 1.9.3, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5
|
24
|
+
* Ruby 1.8.7, 1.9.2, 1.9.3, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5
|
23
25
|
|
24
|
-
* Rails 3.0.x, 3.1.x, 3.2.x, 4.0.x, 4.1.x, 5.0.x
|
26
|
+
* Rails 3.0.x, 3.1.x, 3.2.x, 4.0.x, 4.1.x, 5.0.x, 5.1.x, 5.2.x
|
25
27
|
|
26
28
|
## Installation
|
27
29
|
|
@@ -59,10 +61,15 @@ Model 'User':
|
|
59
61
|
[:facebook_id] (scope 'application_id'). Index exists: true
|
60
62
|
[:twitter_id] (scope 'application_id'). Index exists: false
|
61
63
|
[:external_user_id] (scope 'application_id'). Index exists: false
|
62
|
-
[:blob_id]
|
64
|
+
[:blob_id]. Index exists: true
|
63
65
|
```
|
64
66
|
All things with **Index exists: false** are problematic and you should fix it by adding proper DB indexes.
|
65
67
|
|
68
|
+
Consider use one of the following solutions to resolve above issues:
|
69
|
+
* Add proper DB index.
|
70
|
+
* Move unique validation to DB level.
|
71
|
+
More info in the article https://medium.com/@igorkhomenko/rails-make-sure-you-have-proper-db-indexes-for-your-models-unique-validations-ffd0364df26f
|
72
|
+
|
66
73
|
## Copyright
|
67
74
|
|
68
75
|
Copyright © 2017 Igor Khomenko. See LICENSE file for further details.
|
@@ -12,7 +12,6 @@ module UniqueValidationInspector
|
|
12
12
|
|
13
13
|
def initialize(app)
|
14
14
|
@app = app
|
15
|
-
|
16
15
|
end
|
17
16
|
|
18
17
|
def load_everything!
|
@@ -31,16 +30,23 @@ module UniqueValidationInspector
|
|
31
30
|
validators = model.validators.select {|v| v.is_a?(ActiveRecord::Validations::UniquenessValidator) }
|
32
31
|
{:model => model, :validators => validators}
|
33
32
|
end
|
34
|
-
|
35
33
|
end
|
36
34
|
|
37
|
-
def defined_unique_indexes(table_name,
|
35
|
+
def defined_unique_indexes(table_name, field, scope)
|
38
36
|
#https://dev.mysql.com/doc/refman/5.7/en/multiple-column-indexes.html
|
39
|
-
|
40
37
|
columns = []
|
41
|
-
columns +=
|
42
|
-
columns
|
43
|
-
|
38
|
+
columns += field
|
39
|
+
columns = columns + Array(scope) if scope
|
40
|
+
|
41
|
+
unique_indexes(table_name).any? do |index_def|
|
42
|
+
columns.map(&:to_s) == index_def.columns
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def unique_indexes(table_name)
|
49
|
+
ActiveRecord::Base.connection.indexes(table_name.to_sym).select{|i| i.unique }
|
44
50
|
end
|
45
51
|
|
46
52
|
end
|
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "unique_validation_inspector"
|
8
8
|
spec.version = UniqueValidationInspector::VERSION
|
9
9
|
spec.authors = ["Igor Khomenko"]
|
10
|
-
spec.email = ["
|
10
|
+
spec.email = ["khomenkoigor@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = "A Rake task that helps you find unique validations in models that do not have proper DB indexes."
|
13
13
|
spec.description = "A Rake task investigates the application's models definition, then tells you unique validations that do not have DB indexes."
|
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.3.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:
|
11
|
+
date: 2018-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -83,7 +83,7 @@ dependencies:
|
|
83
83
|
description: A Rake task investigates the application's models definition, then tells
|
84
84
|
you unique validations that do not have DB indexes.
|
85
85
|
email:
|
86
|
-
-
|
86
|
+
- khomenkoigor@gmail.com
|
87
87
|
executables: []
|
88
88
|
extensions: []
|
89
89
|
extra_rdoc_files: []
|