activerecord-data_integrity 0.1.0 → 0.2.1

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: 15651ea16d6fc6051e45163a15ff512472c440ee173e4c8c9acd9cf3e45e010f
4
- data.tar.gz: 4badc1574b0c1c1329d1f0fdd14e10016a7097113cc6bf098751062d53f68cb3
3
+ metadata.gz: 4320a7b0ab38a21dea7e1e075970d577b02f9fc790efd8007e0c13aa67b8d7d6
4
+ data.tar.gz: 9622a1da1fefc7999ff66a4e2c35bac19423725add0253ce0e2e4a166cb09cd8
5
5
  SHA512:
6
- metadata.gz: 698d90f68b8f72a07f2cbc3e5910d60418a3ac4a2aa881007ebccf5e656d3ee85c52d2140218a42396025cb79d782e6a36406b666ed22dfd6cacd4bbc1df0192
7
- data.tar.gz: 41e5fd22054feeb45b1f53ce9df8d00a4d070dc944690d1e79b4c7f3a8e9c797956bb6e35c75c5bd26c5b0be44683a8da43680fc77516e41f49e4f19db46d819
6
+ metadata.gz: e08de321bc373ec869c0066334d508ac446d76acefbd93a0dc424741168cf98cb38d5c2ae5eb78efe3dae0b0d8aa1049e7057834bb602de4f8e49f62b714d84e
7
+ data.tar.gz: ff262e55e504360e6c67391d061d85b80652f82afd5be5df5723d4256a24239433f6216f50539435eba8e36a98f1910bdff392a4a91fb5638a260b2ff2bbf616
@@ -12,3 +12,7 @@ AllCops:
12
12
 
13
13
  Metrics/LineLength:
14
14
  Max: 110
15
+
16
+ Metrics/BlockLength:
17
+ Exclude:
18
+ - 'spec/**/*'
@@ -12,7 +12,8 @@ script:
12
12
  deploy:
13
13
  provider: rubygems
14
14
  api_key:
15
- secure: ILU6srwid/tAV00OmpcR4hpyTHO8TWK4C1wIYxmt+v0f/g8BuzsaZ/iXLM8aXWu7uRGeyp9jV0kA8Dg4KTCq4FlTazo3u2al7wm840h2KhB/mj/QxN8GBIr6hySQaouwRfzVRpVr7KBcHp10ElBd9GXhVm5v5V/j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HncdxTSeAXf9cZY9c9s7ssJGFoe7DOAWeAU84DhhbCsJ1UL87wOvserpVpaTXVs8tdsP5WSVNUucwl4CE7ewJBwFJMhELVAhzanyCmjFhjc8F2Za9Kpm/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 enforces many issues such as the lack of foreign keys.
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 excludion "removed" rows
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.
@@ -4,4 +4,4 @@
4
4
  require 'bundler/setup'
5
5
  require 'activerecord/data_integrity'
6
6
 
7
- ActiveRecord::DataIntegrity::CLI.new.run
7
+ ActiveRecord::DataIntegrity::CLI.start(ARGV)
@@ -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
- def initialize; end
8
-
9
- def run
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 ||= ActiveRecord::DataIntegrity::Cop.descendants
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].name] ||= []
35
- hash[item[:cop].name] << item
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 name
15
- self.class.name.gsub('ActiveRecord::DataIntegrity::', '').gsub('::', '/')
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(self, subresult ? '.' : false_char)
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveRecord
4
4
  module DataIntegrity
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.1'
6
6
  end
7
7
  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.0
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-16 00:00:00.000000000 Z
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