activerecord-data_integrity 0.1.0 → 0.2.1
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/.rubocop.yml +4 -0
- data/.travis.yml +2 -1
- data/README.md +12 -7
- data/exe/data_integrity +1 -1
- data/lib/active_record/data_integrity/cli.rb +25 -5
- data/lib/active_record/data_integrity/collector.rb +2 -2
- data/lib/active_record/data_integrity/cop/cop.rb +6 -3
- data/lib/active_record/data_integrity/options.rb +20 -0
- data/lib/active_record/data_integrity/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4320a7b0ab38a21dea7e1e075970d577b02f9fc790efd8007e0c13aa67b8d7d6
|
|
4
|
+
data.tar.gz: 9622a1da1fefc7999ff66a4e2c35bac19423725add0253ce0e2e4a166cb09cd8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e08de321bc373ec869c0066334d508ac446d76acefbd93a0dc424741168cf98cb38d5c2ae5eb78efe3dae0b0d8aa1049e7057834bb602de4f8e49f62b714d84e
|
|
7
|
+
data.tar.gz: ff262e55e504360e6c67391d061d85b80652f82afd5be5df5723d4256a24239433f6216f50539435eba8e36a98f1910bdff392a4a91fb5638a260b2ff2bbf616
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
|
@@ -12,7 +12,8 @@ script:
|
|
|
12
12
|
deploy:
|
|
13
13
|
provider: rubygems
|
|
14
14
|
api_key:
|
|
15
|
-
secure:
|
|
15
|
+
secure: Q3gyExePLXgWljK9mibX9A2AJR0GMjDJVMLYzJ4hu0vdc6+QwOTFcsDgqdhpqoOfrIBAVT5Hp+ry7slmwB8YzLMvRvM8tft7NjB2kpZE03uitDE9uYoYM9cKnguLDf3B5djLHcEy3T1ujD4wziEeU+SvVyyk/1jb1kSBRu2o4foDdveo8IB5m/DLBkz3YUYUVPd+SlyJPiVTitTRYIO5T2esENhNQHCEro1DVbXUC3e3KHuE38Nwpl6rcm54KCwp8Ji3f6135/XETxhPFRF9L5K6pLwAh6lqxEibspI9bYVOpVfNhqKvjqOY/zn+FHCgSAFIDKU1UQjAsBbYQMpIizL9gow0jQU4z87wM47wvFdZHOPtNEOivqIyiOccFxDT+X5qmqRmUY4FDi3wAqze3WXJkUadpoNPzZ78Xcl2ZVnPKbFMY2Omp7d0ghHkI31WGePKVT37S47vZZeCNPYgfMEWthNJK0Rch6nAGZBnolQoQKB/3n0ue0b3ik0pYgQkrZv/aG/3Dy5Od3aAzI84lRI78AzitiChxNZX+3c8hKtWZteBwHncdxTSeAXf9cZY9c9s7ssJGFoe7DOAWeAU84DhhbCsJ1UL87wOvserpVpaTXVs8tdsP5WSVNUucwl4CE7ewJBwFJMhELVAhzanyCmjFhjc8F2Za9Kpm/xQ7EM=
|
|
16
16
|
gem: activerecord-data_integrity
|
|
17
17
|
on:
|
|
18
18
|
tags: true
|
|
19
|
+
repo: dsalahutdinov/activerecord-data_integrity
|
data/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
# ActiveRecord::DataIntegrity
|
|
5
5
|
|
|
6
6
|
Checks your ActiveRecord models to match data integrity principles and rules.
|
|
7
|
-
Out of the box it
|
|
7
|
+
Out of the box it detects many issues such as the lack of foreign keys.
|
|
8
8
|
|
|
9
9
|
## Intallation
|
|
10
10
|
```ruby
|
|
@@ -29,12 +29,19 @@ Accordance/TablePresence: Stat::Hourly has no underlying table hourly_stats
|
|
|
29
29
|
...
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
+
## Options
|
|
33
|
+
|
|
34
|
+
Check only specified database rules:
|
|
35
|
+
```
|
|
36
|
+
bundle exec data_integrity --only HasMany/ForeignKey,BelongsTo/ForeignKey
|
|
37
|
+
```
|
|
38
|
+
|
|
32
39
|
## Supported Issues
|
|
33
40
|
|
|
34
41
|
For now tool checks the following issues:
|
|
35
|
-
- [x] The lack of database foreign keys for belongs_to/has_many associations
|
|
36
|
-
- [x] The lack of not-null constraint for the columns with presence validation
|
|
37
|
-
- [x] Inclusion validated colums should have `enum` data type
|
|
42
|
+
- [x] The lack of database foreign keys for belongs_to/has_many associations (`HasMany/ForeignKey` and `BelongsTo/ForeignKey` rule)
|
|
43
|
+
- [x] The lack of not-null constraint for the columns with presence validation (`Validation/Presence` rule)
|
|
44
|
+
- [x] Inclusion validated colums should have `enum` data type (`Validation/Inclusion` rule)
|
|
38
45
|
|
|
39
46
|
## Roadmap (TODO & Help Wanted)
|
|
40
47
|
|
|
@@ -42,14 +49,12 @@ For now tool checks the following issues:
|
|
|
42
49
|
- [ ] presence of `dependend` option set for association and not confliction with underlying `ON DELETE` option of foreign key contraint
|
|
43
50
|
- [ ] check for foreign keys to have bigint data type
|
|
44
51
|
- [ ] presence of index for the foreign keys search
|
|
45
|
-
- [ ] checks for paranoia models and indexes
|
|
52
|
+
- [ ] checks for paranoia models and indexes exclusion "removed" rows
|
|
46
53
|
|
|
47
54
|
2) Config for exluding some rules for the specific models (rubocop like)
|
|
48
55
|
|
|
49
56
|
3) Autofix for the fixing the issue, mostly by generating safe migrations
|
|
50
57
|
|
|
51
|
-
4) Possibility to run with checking only specific rule
|
|
52
|
-
|
|
53
58
|
## Contributing
|
|
54
59
|
|
|
55
60
|
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/activerecord-data_integrity.
|
data/exe/data_integrity
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'thor'
|
|
4
|
+
require_relative 'options'
|
|
5
|
+
|
|
3
6
|
module ActiveRecord
|
|
4
7
|
module DataIntegrity
|
|
5
8
|
# CLI application class
|
|
6
|
-
class CLI
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
class CLI < Thor
|
|
10
|
+
attr_reader :options
|
|
11
|
+
|
|
12
|
+
desc 'check [OPTIONS]', 'Runs the data integrity check'
|
|
13
|
+
method_option :only,
|
|
14
|
+
type: :string,
|
|
15
|
+
desc: 'List of the rules to check, separated with comma' \
|
|
16
|
+
', e.g. --only BelongsTo/ForeignKey,Accordance/PrimaryKey'
|
|
17
|
+
def check(_args = ARGV)
|
|
18
|
+
@options = Options.new(options)
|
|
10
19
|
require_rails
|
|
11
20
|
|
|
12
21
|
results = cops.map do |cop_class|
|
|
@@ -19,11 +28,22 @@ module ActiveRecord
|
|
|
19
28
|
|
|
20
29
|
exit(1) if results.include?(false)
|
|
21
30
|
end
|
|
31
|
+
default_task :check
|
|
32
|
+
|
|
33
|
+
desc 'version', 'Print the current version'
|
|
34
|
+
def version
|
|
35
|
+
puts ActiveRecord::DataIntegrity::VERSION
|
|
36
|
+
end
|
|
37
|
+
map %w[--version -v] => :version
|
|
22
38
|
|
|
23
39
|
private
|
|
24
40
|
|
|
25
41
|
def cops
|
|
26
|
-
@cops ||=
|
|
42
|
+
@cops ||= begin
|
|
43
|
+
ActiveRecord::DataIntegrity::Cop.descendants.select do |cop|
|
|
44
|
+
options.only.empty? || cop.cop_name.in?(options.only)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
27
47
|
end
|
|
28
48
|
|
|
29
49
|
def require_rails
|
|
@@ -31,8 +31,8 @@ module ActiveRecord
|
|
|
31
31
|
|
|
32
32
|
def group_data_by_cop_name
|
|
33
33
|
data.each_with_object({}) do |item, hash|
|
|
34
|
-
hash[item[:cop].
|
|
35
|
-
hash[item[:cop].
|
|
34
|
+
hash[item[:cop].class.cop_name] ||= []
|
|
35
|
+
hash[item[:cop].class.cop_name] << item
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
38
|
end
|
|
@@ -11,8 +11,8 @@ module ActiveRecord
|
|
|
11
11
|
@model = model
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
def
|
|
15
|
-
|
|
14
|
+
def self.cop_name
|
|
15
|
+
name.gsub('ActiveRecord::DataIntegrity::', '').gsub('::', '/')
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def log(msg)
|
|
@@ -20,7 +20,10 @@ module ActiveRecord
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def progress(subresult, false_char = 'E')
|
|
23
|
-
ActiveRecord::DataIntegrity::Collector.progress(
|
|
23
|
+
ActiveRecord::DataIntegrity::Collector.progress(
|
|
24
|
+
self,
|
|
25
|
+
subresult ? Rainbow('.').green : Rainbow(false_char).red
|
|
26
|
+
)
|
|
24
27
|
end
|
|
25
28
|
end
|
|
26
29
|
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'optparse'
|
|
4
|
+
|
|
5
|
+
module ActiveRecord
|
|
6
|
+
module DataIntegrity
|
|
7
|
+
# Options parser
|
|
8
|
+
class Options
|
|
9
|
+
def initialize(options)
|
|
10
|
+
@options = {
|
|
11
|
+
only: options.only? ? options[:only].to_s.split(',') : nil
|
|
12
|
+
}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def only
|
|
16
|
+
@options[:only] || []
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activerecord-data_integrity
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Salahutdinov Dmitry
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-11-
|
|
11
|
+
date: 2018-11-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: pg
|
|
@@ -198,6 +198,7 @@ files:
|
|
|
198
198
|
- lib/active_record/data_integrity/cop/has_many/foreign_key.rb
|
|
199
199
|
- lib/active_record/data_integrity/cop/validation/inclusion.rb
|
|
200
200
|
- lib/active_record/data_integrity/cop/validation/presence.rb
|
|
201
|
+
- lib/active_record/data_integrity/options.rb
|
|
201
202
|
- lib/active_record/data_integrity/version.rb
|
|
202
203
|
- lib/activerecord/data_integrity.rb
|
|
203
204
|
homepage: https://github.com/dsalahutdinov/activerecord-data_integrity
|