database_consistency 0.8.6 → 0.8.11
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 +1 -0
- data/lib/database_consistency/checkers/association_checkers/foreign_key_type_checker.rb +27 -4
- data/lib/database_consistency/checkers/base_checker.rb +8 -4
- data/lib/database_consistency/checkers/validator_checkers/missing_unique_index_checker.rb +1 -0
- data/lib/database_consistency/errors.rb +11 -0
- data/lib/database_consistency/helper.rb +1 -1
- data/lib/database_consistency/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: 964b3ab9787dba65ec8981c690f93ec0b0c5a7848e7e0b835ef2aa9a9a415025
|
4
|
+
data.tar.gz: '09d5264224cf230a7d08157101c16d5fe8fcb180684876265dcb16c6c3ecc3f1'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 661de8be036f7cd5640e6240e3abd605a013bda1fe2b7fcd52243c88d0b0251f9a57ba852117ec75827d125873f982c9c060d991ace7fff296312f7a3bf390c6
|
7
|
+
data.tar.gz: e87befd21bc84b26608b1ded54a6e0199958e4fe9993071db93d511b6ab223c0cb468851f472ab927f7a46f4c2b9d4ce15bb6649a01e64641a1551d05eb6385c
|
data/lib/database_consistency.rb
CHANGED
@@ -6,6 +6,7 @@ require 'database_consistency/version'
|
|
6
6
|
require 'database_consistency/helper'
|
7
7
|
require 'database_consistency/configuration'
|
8
8
|
require 'database_consistency/rescue_error'
|
9
|
+
require 'database_consistency/errors'
|
9
10
|
|
10
11
|
require 'database_consistency/writers/base_writer'
|
11
12
|
require 'database_consistency/writers/simple_writer'
|
@@ -19,10 +19,14 @@ module DatabaseConsistency
|
|
19
19
|
|
20
20
|
# We skip check when:
|
21
21
|
# - association is polymorphic association
|
22
|
+
# - association is has_and_belongs_to_many
|
22
23
|
# - association has `through` option
|
23
24
|
# - associated class doesn't exist
|
24
25
|
def preconditions
|
25
|
-
!association.polymorphic? &&
|
26
|
+
!association.polymorphic? &&
|
27
|
+
association.through_reflection.nil? &&
|
28
|
+
association.klass.present? &&
|
29
|
+
association.macro != :has_and_belongs_to_many
|
26
30
|
rescue NameError
|
27
31
|
false
|
28
32
|
end
|
@@ -51,12 +55,24 @@ module DatabaseConsistency
|
|
51
55
|
|
52
56
|
# @return [String]
|
53
57
|
def base_key
|
54
|
-
@base_key ||=
|
58
|
+
@base_key ||= (
|
59
|
+
if belongs_to_association?
|
60
|
+
association.foreign_key
|
61
|
+
else
|
62
|
+
association.active_record_primary_key
|
63
|
+
end
|
64
|
+
).to_s
|
55
65
|
end
|
56
66
|
|
57
67
|
# @return [String]
|
58
68
|
def associated_key
|
59
|
-
@associated_key ||=
|
69
|
+
@associated_key ||= (
|
70
|
+
if belongs_to_association?
|
71
|
+
association.association_primary_key
|
72
|
+
else
|
73
|
+
association.foreign_key
|
74
|
+
end
|
75
|
+
).to_s
|
60
76
|
end
|
61
77
|
|
62
78
|
# @return [ActiveRecord::ConnectionAdapters::Column]
|
@@ -79,7 +95,14 @@ module DatabaseConsistency
|
|
79
95
|
#
|
80
96
|
# @return [ActiveRecord::ConnectionAdapters::Column]
|
81
97
|
def column(model, column_name)
|
82
|
-
model.connection.columns(model.table_name).find { |column| column.name == column_name
|
98
|
+
model.connection.columns(model.table_name).find { |column| column.name == column_name } ||
|
99
|
+
(raise Errors::MissingField, missing_field_error(model.table_name, column_name))
|
100
|
+
end
|
101
|
+
|
102
|
+
# @return [String]
|
103
|
+
def missing_field_error(table_name, column_name)
|
104
|
+
"Association (#{association.name}) of class (#{association.active_record}) relies on "\
|
105
|
+
"field (#{column_name}) of table (#{table_name}) but it is missing."
|
83
106
|
end
|
84
107
|
|
85
108
|
# @param [ActiveRecord::ConnectionAdapters::Column] column
|
@@ -16,16 +16,20 @@ module DatabaseConsistency
|
|
16
16
|
@checker_name ||= name.split('::').last
|
17
17
|
end
|
18
18
|
|
19
|
-
# @
|
20
|
-
|
19
|
+
# @param [Boolean] catch_errors
|
20
|
+
#
|
21
|
+
# @return [Hash, File, nil]
|
22
|
+
def report(catch_errors = true)
|
21
23
|
return unless preconditions
|
22
24
|
|
23
25
|
@report ||= check
|
24
26
|
rescue StandardError => e
|
27
|
+
raise e unless catch_errors
|
28
|
+
|
25
29
|
RescueError.call(e)
|
26
30
|
end
|
27
31
|
|
28
|
-
# @return [Hash, nil]
|
32
|
+
# @return [Hash, File, nil]
|
29
33
|
def report_if_enabled?(configuration)
|
30
34
|
report if enabled?(configuration)
|
31
35
|
end
|
@@ -62,7 +66,7 @@ module DatabaseConsistency
|
|
62
66
|
raise NotImplementedError
|
63
67
|
end
|
64
68
|
|
65
|
-
# @return [
|
69
|
+
# @return [OpenStruct]
|
66
70
|
def report_template(status, message = nil)
|
67
71
|
OpenStruct.new(
|
68
72
|
checker_name: checker_name,
|
@@ -8,7 +8,7 @@ module DatabaseConsistency
|
|
8
8
|
# Returns list of models to check
|
9
9
|
def models
|
10
10
|
ActiveRecord::Base.descendants.delete_if(&:abstract_class?).delete_if do |klass|
|
11
|
-
!klass.connection.table_exists?(klass.table_name)
|
11
|
+
!klass.connection.table_exists?(klass.table_name) || klass.name.include?('HABTM_')
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
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.8.
|
4
|
+
version: 0.8.11
|
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-
|
11
|
+
date: 2020-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -149,6 +149,7 @@ files:
|
|
149
149
|
- lib/database_consistency/databases/factory.rb
|
150
150
|
- lib/database_consistency/databases/types/base.rb
|
151
151
|
- lib/database_consistency/databases/types/sqlite.rb
|
152
|
+
- lib/database_consistency/errors.rb
|
152
153
|
- lib/database_consistency/helper.rb
|
153
154
|
- lib/database_consistency/processors/associations_processor.rb
|
154
155
|
- lib/database_consistency/processors/base_processor.rb
|