database_consistency 0.6.9 → 0.7.0

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: 56965231dae6fdb2965490bad30361b322f4305c960504ebbca47c49ed03a7fc
4
- data.tar.gz: 5d29b7c7096b799d79cd52848e28d5fda4dd8d0b27ea6391b9ee3851d4287343
3
+ metadata.gz: 1c53856db0000e888ce0b385047256cd0876cf1fad3e65c2c664ed903eeea876
4
+ data.tar.gz: 9d3511a92644e1e47fbbbc2a4a35a5bdce4ac4f3a7082fa4219d53a7638c8ec3
5
5
  SHA512:
6
- metadata.gz: 81a45931d30f3a43e6a84c643861d931fc99bd1f9bebf3d468d0ce44dbb985932bfff2073d96a83acc795a052858f29a6b0b83d940119a1b51a76ff9ed326b3b
7
- data.tar.gz: e5941f1c7164476948e0eee87a9a78fc9bbae94062acccfa07514b234000e684caf9f2014a0655646dc24d0ac57de8848b97b3c975c6cccdc8fe1016ea412a42
6
+ metadata.gz: 86eed4e23e719d58de24cb8f6d641c9b9eb47a405e5a82204fe61a0464b3e6186eff9eab8812fe810fc38c44dd093ac05f3eca2539553ed8f43ada5b3ba72d14
7
+ data.tar.gz: f1db1582acbcd9a073b4a346dac0d282f2262aeb31f680231fc189a2cdf73de9d63468f700848a392a0fc8927c56da61c3953db348f1edd36869b9f5e8fe0d29
@@ -11,15 +11,15 @@ require 'database_consistency/writers/base_writer'
11
11
  require 'database_consistency/writers/simple_writer'
12
12
 
13
13
  require 'database_consistency/checkers/base_checker'
14
- require 'database_consistency/checkers/association_checker'
15
- require 'database_consistency/checkers/column_checker'
16
- require 'database_consistency/checkers/validator_checker'
17
-
18
- require 'database_consistency/checkers/column_presence_checker'
19
- require 'database_consistency/checkers/null_constraint_checker'
20
- require 'database_consistency/checkers/belongs_to_presence_checker'
21
- require 'database_consistency/checkers/missing_unique_index_checker'
22
- require 'database_consistency/checkers/missing_index_checker'
14
+ require 'database_consistency/checkers/association_checkers/association_checker'
15
+ require 'database_consistency/checkers/association_checkers/missing_index_checker'
16
+ require 'database_consistency/checkers/column_checkers/column_checker'
17
+ require 'database_consistency/checkers/column_checkers/null_constraint_checker'
18
+ require 'database_consistency/checkers/column_checkers/length_constraint_checker'
19
+ require 'database_consistency/checkers/validator_checkers/validator_checker'
20
+ require 'database_consistency/checkers/validator_checkers/column_presence_checker'
21
+ require 'database_consistency/checkers/validator_checkers/belongs_to_presence_checker'
22
+ require 'database_consistency/checkers/validator_checkers/missing_unique_index_checker'
23
23
 
24
24
  require 'database_consistency/processors/base_processor'
25
25
  require 'database_consistency/processors/associations_processor'
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DatabaseConsistency
4
+ module Checkers
5
+ # This class checks missing presence validator
6
+ class LengthConstraintChecker < ColumnChecker
7
+ # Message templates
8
+ VALIDATOR_MISSING = 'column has limit in the database but do not have length validator'
9
+ GREATER_LIMIT = 'column has greater limit in the database than in length validator'
10
+ LOWER_LIMIT = 'column has lower limit in the database than in length validator'
11
+
12
+ VALIDATOR_CLASS =
13
+ if defined?(ActiveRecord::Validations::LengthValidator)
14
+ ActiveRecord::Validations::LengthValidator
15
+ else
16
+ ActiveModel::Validations::LengthValidator
17
+ end
18
+
19
+ private
20
+
21
+ # We skip check when:
22
+ # - column hasn't limit constraint
23
+ def preconditions
24
+ !column.limit.nil?
25
+ end
26
+
27
+ # Table of possible statuses
28
+ # | validation | status |
29
+ # | ---------- | ------- |
30
+ # | provided | ok |
31
+ # | small | warning |
32
+ # | missing | fail |
33
+ def check
34
+ return report_template(:fail, VALIDATOR_MISSING) unless validator
35
+
36
+ if valid?(:==)
37
+ report_template(:ok)
38
+ elsif valid?(:<)
39
+ report_template(:warning, GREATER_LIMIT)
40
+ else
41
+ report_template(:fail, LOWER_LIMIT)
42
+ end
43
+ end
44
+
45
+ def valid?(sign)
46
+ %i[maximum is].each do |option|
47
+ return validator.options[option].public_send(sign, column.limit) if validator.options[option]
48
+ end
49
+
50
+ false
51
+ end
52
+
53
+ def validator
54
+ @validator ||= model.validators.grep(VALIDATOR_CLASS).find do |validator|
55
+ Helper.check_inclusion?(validator.attributes, column.name)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -5,7 +5,8 @@ module DatabaseConsistency
5
5
  # The class to process columns
6
6
  class ColumnsProcessor < BaseProcessor
7
7
  CHECKERS = [
8
- Checkers::NullConstraintChecker
8
+ Checkers::NullConstraintChecker,
9
+ Checkers::LengthConstraintChecker
9
10
  ].freeze
10
11
 
11
12
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DatabaseConsistency
4
- VERSION = '0.6.9'
4
+ VERSION = '0.7.0'
5
5
  end
@@ -35,6 +35,7 @@ module DatabaseConsistency
35
35
  def status_text(result)
36
36
  color = case result.status
37
37
  when :ok then :green
38
+ when :warning then :yellow
38
39
  when :fail then :red
39
40
  end
40
41
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: database_consistency
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.9
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeniy Demin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-19 00:00:00.000000000 Z
11
+ date: 2019-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -138,15 +138,16 @@ extra_rdoc_files: []
138
138
  files:
139
139
  - bin/database_consistency
140
140
  - lib/database_consistency.rb
141
- - lib/database_consistency/checkers/association_checker.rb
141
+ - lib/database_consistency/checkers/association_checkers/association_checker.rb
142
+ - lib/database_consistency/checkers/association_checkers/missing_index_checker.rb
142
143
  - lib/database_consistency/checkers/base_checker.rb
143
- - lib/database_consistency/checkers/belongs_to_presence_checker.rb
144
- - lib/database_consistency/checkers/column_checker.rb
145
- - lib/database_consistency/checkers/column_presence_checker.rb
146
- - lib/database_consistency/checkers/missing_index_checker.rb
147
- - lib/database_consistency/checkers/missing_unique_index_checker.rb
148
- - lib/database_consistency/checkers/null_constraint_checker.rb
149
- - lib/database_consistency/checkers/validator_checker.rb
144
+ - lib/database_consistency/checkers/column_checkers/column_checker.rb
145
+ - lib/database_consistency/checkers/column_checkers/length_constraint_checker.rb
146
+ - lib/database_consistency/checkers/column_checkers/null_constraint_checker.rb
147
+ - lib/database_consistency/checkers/validator_checkers/belongs_to_presence_checker.rb
148
+ - lib/database_consistency/checkers/validator_checkers/column_presence_checker.rb
149
+ - lib/database_consistency/checkers/validator_checkers/missing_unique_index_checker.rb
150
+ - lib/database_consistency/checkers/validator_checkers/validator_checker.rb
150
151
  - lib/database_consistency/configuration.rb
151
152
  - lib/database_consistency/helper.rb
152
153
  - lib/database_consistency/processors/associations_processor.rb