database_consistency 1.7.22 → 1.7.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f824e179d3bff9cb27c82f046c549fc1cbe89a5d31c6553be49658d45d088816
4
- data.tar.gz: c3f147843c216b3dc4672c47819a960839c7d4966b3c42e249b37f38de89d4ee
3
+ metadata.gz: b29d0d23f3eda8be6c71719df374c21bf7c69f749bdd5d9e71b658b7194e0a7a
4
+ data.tar.gz: 4dc387034661a53ce80a65513696da3bb5264b4097d1928268ca2cced6a2b082
5
5
  SHA512:
6
- metadata.gz: d7ce83332d2487b9b284daaad05ba34d3f98415ef163a93f9e19c808432b247116440379c712d73ca4da05c5cfbd64496453175b69ea41e682f15e4e5cbc9d44
7
- data.tar.gz: 74506e33950ee7a9c768880f744e87719d4418392e41a7993bfeb507f7a15039654eec4eb55ab5ab9f18f0dfb1eca29d16cd8765069d495b1b1baa35c2414e58
6
+ metadata.gz: 55f5c65ea75f3384bac11404204522c850d4637c884a6d08cc2b00201e874f74b246410527f6d619e41e35ef078bcca1f7dfce34709621a0a9d4c463b46d727f
7
+ data.tar.gz: 6bf767f48dfb95cbfce02f9a0fe49718adff8c2afc2e7ae7d74b9496b7991f11bc9f4da10c682cb36dbab310b92c7afc01f9b0b0073c03adaa51000f3f4d216d
@@ -44,7 +44,7 @@ module DatabaseConsistency
44
44
  def verify_enum
45
45
  values = enum.values.uniq
46
46
 
47
- if enum_column_values == values
47
+ if enum_column_values.sort == values.sort
48
48
  report_template(:ok, values)
49
49
  else
50
50
  report_template(:fail, values, error_slug: :enum_values_inconsistent_with_ar_enum)
@@ -54,7 +54,7 @@ module DatabaseConsistency
54
54
  def verify_inclusion_validator
55
55
  values = validator_values(inclusion_validator).uniq
56
56
 
57
- if enum_column_values == values
57
+ if enum_column_values.sort == values.sort
58
58
  report_template(:ok, values)
59
59
  else
60
60
  report_template(:fail, values, error_slug: :enum_values_inconsistent_with_inclusion)
@@ -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,12 @@ module DatabaseConsistency
48
48
  value
49
49
  end
50
50
 
51
+ def database_enabled?(name)
52
+ value = configuration.dig('DatabaseConsistencyDatabases', name, 'enabled')
53
+
54
+ value.nil? ? true : value
55
+ end
56
+
51
57
  private
52
58
 
53
59
  attr_reader :configuration
@@ -14,11 +14,10 @@ module DatabaseConsistency
14
14
 
15
15
  private
16
16
 
17
- def check # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
17
+ def check # rubocop:disable Metrics/MethodLength
18
18
  Helper.models.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)
20
+ next unless model_enabled?(model)
22
21
 
23
22
  Helper.first_level_associations(model).flat_map do |association|
24
23
  DebugContext.with(association: association.name) do
@@ -43,6 +43,11 @@ module DatabaseConsistency
43
43
 
44
44
  private
45
45
 
46
+ def model_enabled?(model)
47
+ configuration.database_enabled?(Helper.database_name(model)) &&
48
+ configuration.enabled?(model.name.to_s)
49
+ end
50
+
46
51
  def check
47
52
  raise NotImplementedError
48
53
  end
@@ -15,11 +15,10 @@ module DatabaseConsistency
15
15
 
16
16
  private
17
17
 
18
- def check # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
18
+ def check # rubocop:disable Metrics/MethodLength
19
19
  Helper.parent_models.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)
21
+ next unless model_enabled?(model)
23
22
 
24
23
  model.columns.flat_map do |column|
25
24
  DebugContext.with(column: column.name) do
@@ -10,11 +10,10 @@ module DatabaseConsistency
10
10
 
11
11
  private
12
12
 
13
- def check # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
13
+ def check # rubocop:disable Metrics/MethodLength
14
14
  Helper.models.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)
16
+ next unless model_enabled?(model)
18
17
 
19
18
  model.defined_enums.keys.flat_map do |enum|
20
19
  DebugContext.with(enum: enum) do
@@ -15,8 +15,7 @@ module DatabaseConsistency
15
15
  def check # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
16
16
  Helper.parent_models.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)
18
+ next unless model_enabled?(model)
20
19
 
21
20
  indexes = model.connection.indexes(model.table_name)
22
21
 
@@ -10,11 +10,10 @@ module DatabaseConsistency
10
10
 
11
11
  private
12
12
 
13
- def check # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
13
+ def check
14
14
  Helper.project_models.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)
16
+ next unless model_enabled?(model)
18
17
 
19
18
  enabled_checkers.flat_map do |checker_class|
20
19
  DebugContext.with(checker: checker_class) do
@@ -11,11 +11,10 @@ module DatabaseConsistency
11
11
  private
12
12
 
13
13
  # @return [Array<Hash>]
14
- def check # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
14
+ def check # rubocop:disable Metrics/MethodLength
15
15
  Helper.parent_models.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)
17
+ next unless model_enabled?(model)
19
18
 
20
19
  model._validators.flat_map do |attribute, validators|
21
20
  DebugContext.with(attribute: attribute) do
@@ -12,11 +12,10 @@ module DatabaseConsistency
12
12
  private
13
13
 
14
14
  # @return [Array<Hash>]
15
- def check # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
15
+ def check # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
16
16
  Helper.parent_models.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)
18
+ next unless model_enabled?(model)
20
19
 
21
20
  model.validators.flat_map do |validator|
22
21
  next unless validator.respond_to?(:attributes)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DatabaseConsistency
4
- VERSION = '1.7.22'
4
+ VERSION = '1.7.24'
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.22
4
+ version: 1.7.24
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-11-08 00:00:00.000000000 Z
11
+ date: 2024-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord