database_consistency 1.7.23 → 1.7.25

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: fa19d97c8acb835f248d400cf2083c32e8aa409c65155d997710d9bc2cda0c59
4
- data.tar.gz: a598e7238e279205af65c4101b0f8773bb90b6b816bed18850892a8d9cca4a0f
3
+ metadata.gz: 6a60adb5b04de89499434019dd7ae4d0281799fc457122de1d01ad825d9d74e1
4
+ data.tar.gz: 3cfe216adacba3de2df73bf8cc353ce56bbdae93c0b4ada74b860cd89422f173
5
5
  SHA512:
6
- metadata.gz: fb372c25d9da1c239739fbc4688f98f853ae8e17fd7ac238f8eeb4b359bbd5314d0a74eadeb38e783cf3ab383f38fb0762adfd956cc392879d03b1db5d68ac8a
7
- data.tar.gz: 0af3245696790d32ac16cf805038b110e8788390c3162646fcc4fb9f2e85bc343aab8db801decbcaa209bf6cf3a2db0f1f968c99bc0a016f8582e67752b56dfc
6
+ metadata.gz: d522414bc1680d596f9207c95615265befd75535e145c43bd7056c823a160a3620e4a9f5ce28b04b0d00878349e8a21d5b58fda669b6510bd714a355791aa8c6
7
+ data.tar.gz: be1853d66bf896d3ab6eae46684e8533177d90394de2d7360e2e613a3b61e050578fdd0b48a1b357c26171b4c14fedf54f74f064ba0854bdb17026730e2b58a9
@@ -45,8 +45,14 @@ module DatabaseConsistency
45
45
  end
46
46
 
47
47
  def valid?(sign)
48
- %i[maximum is].each do |option|
49
- return validator.options[option].public_send(sign, column.limit) if validator.options[option]
48
+ %i[maximum is].each do |key|
49
+ option = validator.options[key]
50
+ next unless option
51
+
52
+ # skipping runtime-calculated limits
53
+ return true if option.is_a?(Proc) || option.is_a?(Symbol)
54
+
55
+ return option.public_send(sign, column.limit)
50
56
  end
51
57
 
52
58
  false
@@ -48,6 +48,16 @@ module DatabaseConsistency
48
48
  value
49
49
  end
50
50
 
51
+ def model_enabled?(model)
52
+ database_enabled?(Helper.database_name(model)) && enabled?(model.name.to_s)
53
+ end
54
+
55
+ def database_enabled?(name)
56
+ value = configuration.dig('DatabaseConsistencyDatabases', name, 'enabled')
57
+
58
+ value.nil? ? true : value
59
+ end
60
+
51
61
  private
52
62
 
53
63
  attr_reader :configuration
@@ -29,17 +29,19 @@ module DatabaseConsistency
29
29
  end
30
30
  end
31
31
 
32
- def project_models
32
+ def project_models(configuration)
33
33
  ActiveRecord::Base.descendants.select do |klass|
34
+ next unless configuration.model_enabled?(klass)
35
+
34
36
  project_klass?(klass) && connected?(klass)
35
37
  end
36
38
  end
37
39
 
38
40
  # Returns list of models to check
39
- def models
40
- project_models.select do |klass|
41
+ def models(configuration)
42
+ project_models(configuration).select do |klass|
41
43
  !klass.abstract_class? &&
42
- klass.connection.table_exists?(klass.table_name) &&
44
+ klass.table_exists? &&
43
45
  !klass.name.include?('HABTM_')
44
46
  end
45
47
  end
@@ -52,8 +54,8 @@ module DatabaseConsistency
52
54
  end
53
55
 
54
56
  # Return list of not inherited models
55
- def parent_models
56
- models.group_by(&:table_name).each_value.flat_map do |models|
57
+ def parent_models(configuration)
58
+ models(configuration).group_by(&:table_name).each_value.flat_map do |models|
57
59
  models.reject { |model| models.include?(model.superclass) }
58
60
  end
59
61
  end
@@ -65,6 +67,8 @@ module DatabaseConsistency
65
67
  return true unless Module.respond_to?(:const_source_location) && defined?(Bundler)
66
68
 
67
69
  !Module.const_source_location(klass.to_s).first.to_s.include?(Bundler.bundle_path.to_s)
70
+ rescue NameError
71
+ false
68
72
  end
69
73
 
70
74
  # @return [Boolean]
@@ -14,12 +14,9 @@ module DatabaseConsistency
14
14
 
15
15
  private
16
16
 
17
- def check # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
18
- Helper.models.flat_map do |model|
17
+ def check # rubocop:disable Metrics/MethodLength
18
+ Helper.models(configuration).flat_map do |model|
19
19
  DebugContext.with(model: model.name) do
20
- next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
21
- configuration.enabled?(model.name.to_s)
22
-
23
20
  Helper.first_level_associations(model).flat_map do |association|
24
21
  DebugContext.with(association: association.name) do
25
22
  enabled_checkers.flat_map do |checker_class|
@@ -15,12 +15,9 @@ module DatabaseConsistency
15
15
 
16
16
  private
17
17
 
18
- def check # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
19
- Helper.parent_models.flat_map do |model|
18
+ def check # rubocop:disable Metrics/MethodLength
19
+ Helper.parent_models(configuration).flat_map do |model|
20
20
  DebugContext.with(model: model.name) do
21
- next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
22
- configuration.enabled?(model.name.to_s)
23
-
24
21
  model.columns.flat_map do |column|
25
22
  DebugContext.with(column: column.name) do
26
23
  enabled_checkers.flat_map do |checker_class|
@@ -10,12 +10,9 @@ module DatabaseConsistency
10
10
 
11
11
  private
12
12
 
13
- def check # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
14
- Helper.models.flat_map do |model|
13
+ def check # rubocop:disable Metrics/MethodLength
14
+ Helper.models(configuration).flat_map do |model|
15
15
  DebugContext.with(model: model.name) do
16
- next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
17
- configuration.enabled?(model.name.to_s)
18
-
19
16
  model.defined_enums.keys.flat_map do |enum|
20
17
  DebugContext.with(enum: enum) do
21
18
  enabled_checkers.flat_map do |checker_class|
@@ -13,11 +13,8 @@ module DatabaseConsistency
13
13
  private
14
14
 
15
15
  def check # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
16
- Helper.parent_models.flat_map do |model|
16
+ Helper.parent_models(configuration).flat_map do |model|
17
17
  DebugContext.with(model: model.name) do
18
- next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
19
- configuration.enabled?(model.name.to_s)
20
-
21
18
  indexes = model.connection.indexes(model.table_name)
22
19
 
23
20
  indexes.flat_map do |index|
@@ -10,12 +10,9 @@ module DatabaseConsistency
10
10
 
11
11
  private
12
12
 
13
- def check # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
14
- Helper.project_models.flat_map do |model|
13
+ def check
14
+ Helper.project_models(configuration).flat_map do |model|
15
15
  DebugContext.with(model: model.name) do
16
- next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
17
- configuration.enabled?(model.name.to_s)
18
-
19
16
  enabled_checkers.flat_map do |checker_class|
20
17
  DebugContext.with(checker: checker_class) do
21
18
  checker = checker_class.new(model)
@@ -11,12 +11,9 @@ module DatabaseConsistency
11
11
  private
12
12
 
13
13
  # @return [Array<Hash>]
14
- def check # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
15
- Helper.parent_models.flat_map do |model|
14
+ def check # rubocop:disable Metrics/MethodLength
15
+ Helper.parent_models(configuration).flat_map do |model|
16
16
  DebugContext.with(model: model.name) do
17
- next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
18
- configuration.enabled?(model.name.to_s)
19
-
20
17
  model._validators.flat_map do |attribute, validators|
21
18
  DebugContext.with(attribute: attribute) do
22
19
  next unless attribute
@@ -12,12 +12,9 @@ module DatabaseConsistency
12
12
  private
13
13
 
14
14
  # @return [Array<Hash>]
15
- def check # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
16
- Helper.parent_models.flat_map do |model|
15
+ def check # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
16
+ Helper.parent_models(configuration).flat_map do |model|
17
17
  DebugContext.with(model: model.name) do
18
- next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
19
- configuration.enabled?(model.name.to_s)
20
-
21
18
  model.validators.flat_map do |validator|
22
19
  next unless validator.respond_to?(:attributes)
23
20
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DatabaseConsistency
4
- VERSION = '1.7.23'
4
+ VERSION = '1.7.25'
5
5
  end
@@ -23,7 +23,13 @@ module DatabaseConsistency
23
23
  end
24
24
 
25
25
  def columns
26
- "%w[#{report.columns.join(' ')}]"
26
+ if report.columns.size > 1
27
+ "%w[#{report.columns.join(' ')}]"
28
+ elsif report.columns.first =~ /[()]/
29
+ "'#{report.columns.first}'"
30
+ else
31
+ ":#{report.columns.first}"
32
+ end
27
33
  end
28
34
 
29
35
  def columns_key
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: 1.7.23
4
+ version: 1.7.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeniy Demin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-18 00:00:00.000000000 Z
11
+ date: 2024-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -126,14 +126,14 @@ dependencies:
126
126
  name: sqlite3
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - ">"
130
130
  - !ruby/object:Gem::Version
131
131
  version: '1.3'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - ">"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '1.3'
139
139
  description: