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 +4 -4
- data/lib/database_consistency.rb +9 -9
- data/lib/database_consistency/checkers/{association_checker.rb → association_checkers/association_checker.rb} +0 -0
- data/lib/database_consistency/checkers/{missing_index_checker.rb → association_checkers/missing_index_checker.rb} +0 -0
- data/lib/database_consistency/checkers/{column_checker.rb → column_checkers/column_checker.rb} +0 -0
- data/lib/database_consistency/checkers/column_checkers/length_constraint_checker.rb +60 -0
- data/lib/database_consistency/checkers/{null_constraint_checker.rb → column_checkers/null_constraint_checker.rb} +0 -0
- data/lib/database_consistency/checkers/{belongs_to_presence_checker.rb → validator_checkers/belongs_to_presence_checker.rb} +0 -0
- data/lib/database_consistency/checkers/{column_presence_checker.rb → validator_checkers/column_presence_checker.rb} +0 -0
- data/lib/database_consistency/checkers/{missing_unique_index_checker.rb → validator_checkers/missing_unique_index_checker.rb} +0 -0
- data/lib/database_consistency/checkers/{validator_checker.rb → validator_checkers/validator_checker.rb} +0 -0
- data/lib/database_consistency/processors/columns_processor.rb +2 -1
- data/lib/database_consistency/version.rb +1 -1
- data/lib/database_consistency/writers/simple_writer.rb +1 -0
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c53856db0000e888ce0b385047256cd0876cf1fad3e65c2c664ed903eeea876
|
4
|
+
data.tar.gz: 9d3511a92644e1e47fbbbc2a4a35a5bdce4ac4f3a7082fa4219d53a7638c8ec3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86eed4e23e719d58de24cb8f6d641c9b9eb47a405e5a82204fe61a0464b3e6186eff9eab8812fe810fc38c44dd093ac05f3eca2539553ed8f43ada5b3ba72d14
|
7
|
+
data.tar.gz: f1db1582acbcd9a073b4a346dac0d282f2262aeb31f680231fc189a2cdf73de9d63468f700848a392a0fc8927c56da61c3953db348f1edd36869b9f5e8fe0d29
|
data/lib/database_consistency.rb
CHANGED
@@ -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/
|
16
|
-
require 'database_consistency/checkers/
|
17
|
-
|
18
|
-
require 'database_consistency/checkers/
|
19
|
-
require 'database_consistency/checkers/
|
20
|
-
require 'database_consistency/checkers/
|
21
|
-
require 'database_consistency/checkers/
|
22
|
-
require 'database_consistency/checkers/
|
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'
|
File without changes
|
File without changes
|
data/lib/database_consistency/checkers/{column_checker.rb → column_checkers/column_checker.rb}
RENAMED
File without changes
|
@@ -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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
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.
|
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-
|
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/
|
144
|
-
- lib/database_consistency/checkers/
|
145
|
-
- lib/database_consistency/checkers/
|
146
|
-
- lib/database_consistency/checkers/
|
147
|
-
- lib/database_consistency/checkers/
|
148
|
-
- lib/database_consistency/checkers/
|
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
|