database_consistency 0.7.9 → 0.8.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: 2d2fdde533c08cebcdc19ded3a2e2b94587304aef759b6a8bee72bddc2ec0ece
4
- data.tar.gz: 5df7c33b8a2cd32686dd3835514bab577eae10cb340709779bca20f942d6de76
3
+ metadata.gz: 4f029e8151f93b3824ea0ba0b7cb0eff4d2a1d22dc76597da6169957bffb7611
4
+ data.tar.gz: b05b3a118134910eabdbf26a936185ad2cfc45df3417b7d8fad3b0f03d505466
5
5
  SHA512:
6
- metadata.gz: c9de96885025f37decdaf6d8fc566dc9f35da9c9a91500c11504c0202b6e28f9d8fbcd5f8a742fc841b42419dbf7ccdd841066eb144391910948a5fbf637fc22
7
- data.tar.gz: 49088e8975bd3b2795ed97f00802ece5204c11b108bbbfa3eff10f52b1b176762094b8cb6fb414fca7dd1616e384974ca2adc847dee39b1902849bb8ee46c24e
6
+ metadata.gz: '05827f5dbbbb745ff76721881eb78669492a3fbadc3949362076b50736f61f0fa1a6c1750780098a12e6fb61389a8e75deb05603e7a3a4c6d7269f3bad3ba78e'
7
+ data.tar.gz: 57796525845caf0652456e5141ec464146b3fd88ddb44ad51247b2a497b0afd108585edea38489c21da59055ffd5045f11e713e64a9e2107fdbe5b213d4d783f
@@ -11,14 +11,19 @@ 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
+
14
15
  require 'database_consistency/checkers/association_checkers/association_checker'
15
16
  require 'database_consistency/checkers/association_checkers/missing_index_checker'
17
+
16
18
  require 'database_consistency/checkers/column_checkers/column_checker'
17
19
  require 'database_consistency/checkers/column_checkers/null_constraint_checker'
18
20
  require 'database_consistency/checkers/column_checkers/length_constraint_checker'
21
+ require 'database_consistency/checkers/column_checkers/primary_key_type_checker'
22
+
19
23
  require 'database_consistency/checkers/validator_checkers/validator_checker'
20
24
  require 'database_consistency/checkers/validator_checkers/belongs_to_presence_checker'
21
25
  require 'database_consistency/checkers/validator_checkers/missing_unique_index_checker'
26
+
22
27
  require 'database_consistency/checkers/validators_fraction_checkers/validators_fraction_checker'
23
28
  require 'database_consistency/checkers/validators_fraction_checkers/column_presence_checker'
24
29
 
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DatabaseConsistency
4
+ module Checkers
5
+ # This class checks missing presence validator
6
+ class PrimaryKeyTypeChecker < ColumnChecker
7
+ # Message templates
8
+ VALIDATOR_MISSING = 'column has int/serial type but recommended to have bigint/bigserial/uuid'
9
+
10
+ private
11
+
12
+ VALID_TYPES = %w[bigserial bigint uuid].freeze
13
+ SQLITE_ADAPTER_NAME = 'SQLite'
14
+
15
+ # We skip check when:
16
+ # - column is not a primary key
17
+ # - database is SQLite3
18
+ def preconditions
19
+ primary_field? && !sqlite?
20
+ end
21
+
22
+ # Table of possible statuses
23
+ # | bigint/bigserial/uuid | status |
24
+ # | --------------------- | ------ |
25
+ # | yes | ok |
26
+ # | no | fail |
27
+ def check
28
+ if valid?
29
+ report_template(:ok)
30
+ else
31
+ report_template(:fail, VALIDATOR_MISSING)
32
+ end
33
+ end
34
+
35
+ # @return [Boolean]
36
+ def valid?
37
+ VALID_TYPES.any? do |type|
38
+ column.sql_type.to_s.match?(type)
39
+ end
40
+ end
41
+
42
+ # @return [Boolean]
43
+ def primary_field?
44
+ column.name.to_s == model.primary_key.to_s
45
+ end
46
+
47
+ # @return [Boolean]
48
+ def sqlite?
49
+ model.connection.adapter_name == SQLITE_ADAPTER_NAME
50
+ end
51
+ end
52
+ end
53
+ end
@@ -6,7 +6,8 @@ module DatabaseConsistency
6
6
  class ColumnsProcessor < BaseProcessor
7
7
  CHECKERS = [
8
8
  Checkers::NullConstraintChecker,
9
- Checkers::LengthConstraintChecker
9
+ Checkers::LengthConstraintChecker,
10
+ Checkers::PrimaryKeyTypeChecker
10
11
  ].freeze
11
12
 
12
13
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DatabaseConsistency
4
- VERSION = '0.7.9'
4
+ VERSION = '0.8.0'
5
5
  end
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.7.9
4
+ version: 0.8.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: 2020-02-20 00:00:00.000000000 Z
11
+ date: 2020-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '10.0'
75
+ version: 12.3.3
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '10.0'
82
+ version: 12.3.3
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -138,6 +138,7 @@ files:
138
138
  - lib/database_consistency/checkers/column_checkers/column_checker.rb
139
139
  - lib/database_consistency/checkers/column_checkers/length_constraint_checker.rb
140
140
  - lib/database_consistency/checkers/column_checkers/null_constraint_checker.rb
141
+ - lib/database_consistency/checkers/column_checkers/primary_key_type_checker.rb
141
142
  - lib/database_consistency/checkers/validator_checkers/belongs_to_presence_checker.rb
142
143
  - lib/database_consistency/checkers/validator_checkers/missing_unique_index_checker.rb
143
144
  - lib/database_consistency/checkers/validator_checkers/validator_checker.rb