database_consistency 0.8.7 → 0.8.8

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: b1dff50eb6317680dc36fc0260a90c4071bfada212d1124169437123b93d1f65
4
- data.tar.gz: 1fcd504bfaed4674386b3af7d53d9d2d2bd2b1f28d2fb65cd3ae1c1c0f1f1eae
3
+ metadata.gz: 406fd80b86af26702bba071b8dabe3d8f238923bd7ef6d04776b014d2c5c5575
4
+ data.tar.gz: b30e6bee8c79233090fb8a94557217a6e2fc72e618b577b858083bf0cd3ba71e
5
5
  SHA512:
6
- metadata.gz: 22aaae1a55a6c7bc6dd3027852cf8e8b0e94e970c06ac445455e1c5abe787be2a273ed9d7f2b7e9c13b5455f827b1bec82d02eb117eed2599c8e90ebd12719ab
7
- data.tar.gz: e9203782f9364aa086c1ee20e03d6497c92ce17d5e5ece293390549ce4e4f3dbeb0ff07980a9be5548558d59527c4e2a5d0c3928b67991ca27d99fa5f9908dfb
6
+ metadata.gz: 72147fa9f0eccd7ac75216fe673757541048b143ea31fbab435a83e7cb10f62d3e45ae19a5e0c8e609515d3033fa7d868deba863fd8d7ba152f50d254fb3f534
7
+ data.tar.gz: 6c172f7b74de5face1e235103a2821d41be08f282a840b756caf73f24285e8cf6f7e1f5ecf5e40f26160a8036c947c335edc5338ef3ca274a989d9353220f04d
@@ -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? && association.through_reflection.nil? && association.klass.present?
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
@@ -91,7 +95,14 @@ module DatabaseConsistency
91
95
  #
92
96
  # @return [ActiveRecord::ConnectionAdapters::Column]
93
97
  def column(model, column_name)
94
- 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."
95
106
  end
96
107
 
97
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
- # @return [Hash, nil]
20
- def report
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 [Hash]
69
+ # @return [OpenStruct]
66
70
  def report_template(status, message = nil)
67
71
  OpenStruct.new(
68
72
  checker_name: checker_name,
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DatabaseConsistency
4
+ module Errors
5
+ # The base error class
6
+ class Base < StandardError; end
7
+
8
+ # The error class for missing field
9
+ class MissingField < Base; end
10
+ end
11
+ end
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DatabaseConsistency
4
- VERSION = '0.8.7'
4
+ VERSION = '0.8.8'
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.8.7
4
+ version: 0.8.8
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-09-23 00:00:00.000000000 Z
11
+ date: 2020-09-24 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