database_consistency 1.7.4 → 1.7.6

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: b620d27a76af3af281a6d433f5d8383ad7b9ba33811785b55a80d33bd6fb8ce6
4
- data.tar.gz: 378a82e286fea3e482c07e30aa02900441f47e44f7a4402b19ed7c0a6edbf6f1
3
+ metadata.gz: 905028bf5f85ba32f99076b621821a83f8b1bbd5b7662ebba0eb84bee85ce5f2
4
+ data.tar.gz: 763574e25561f0eebb64922bc2b1ab2841c3bb791b570b2a62a5d0ee56758742
5
5
  SHA512:
6
- metadata.gz: c756fa1d604909c62a56c51eef6d3f5140debcd5edff683dea4e5fd9f7e1f1ca421d984912b8efb5c7eacc1056bbc87fb1c5a084dda0b4a8c808e32c8df7398d
7
- data.tar.gz: 11d4f560939e6e82f30cab8a479dfbd14e34b80ec67d62f7cc43788466bf7549d3c6841b0367745b257012975f6a89a32c7e3972ed4aff9ef47a4c260ca8bd8b
6
+ metadata.gz: a4ca99f196d02deb4286f3468c46e2a724b585f79fce48b8768c206c72ee9cd07da42f930edbfe457ab64083a118810de19bdf7149f617d0cda8dea490f82e65
7
+ data.tar.gz: df2c8f4c0d7b4a2e7adf1b6a142f37bcc4b6864d8ae216e33848a5a1adec0723698f841b342080f0a2cefde1e98bd9fd21dfe85bf4721d93500c68bbcb2ba455
@@ -2,7 +2,7 @@
2
2
 
3
3
  module DatabaseConsistency
4
4
  module Checkers
5
- # This class checks if non polymorphic +belongs_to+ association has foreign key constraint
5
+ # This class checks that foreign key has a cascade option matching dependent option
6
6
  class ForeignKeyCascadeChecker < AssociationChecker
7
7
  Report = ReportBuilder.define(
8
8
  DatabaseConsistency::Report,
@@ -14,11 +14,11 @@ module DatabaseConsistency
14
14
  )
15
15
 
16
16
  OPTION_TO_CASCADE = {
17
- delete: :cascade,
18
- delete_all: :cascade,
19
- nullify: :nullify,
20
- restrict_with_exception: :restrict,
21
- restrict_with_error: :restrict
17
+ delete: [:cascade],
18
+ delete_all: [:cascade],
19
+ nullify: [:nullify],
20
+ restrict_with_exception: [nil, :restrict],
21
+ restrict_with_error: [nil, :restrict]
22
22
  }.freeze
23
23
 
24
24
  DEPENDENT_OPTIONS = OPTION_TO_CASCADE.keys.freeze
@@ -52,7 +52,7 @@ module DatabaseConsistency
52
52
  end
53
53
 
54
54
  def correlated_cascade_constraint?
55
- required_foreign_key_cascade == foreign_key_on_delete_option
55
+ required_foreign_key_cascade.include?(foreign_key_on_delete_option)
56
56
  end
57
57
 
58
58
  def dependent_option
@@ -2,7 +2,7 @@
2
2
 
3
3
  module DatabaseConsistency
4
4
  module Checkers
5
- # The base class for table checkers
5
+ # The base class for column checkers
6
6
  class ColumnChecker < BaseChecker
7
7
  attr_reader :model, :column
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module DatabaseConsistency
4
4
  module Checkers
5
- # This class checks missing presence validator
5
+ # This class checks the database enum values and ActiveRecord's enum values/inclusion validations are aligned
6
6
  class EnumValueChecker < ColumnChecker
7
7
  Report = ReportBuilder.define(
8
8
  DatabaseConsistency::Report,
@@ -2,7 +2,7 @@
2
2
 
3
3
  module DatabaseConsistency
4
4
  module Checkers
5
- # This class checks missing presence validator
5
+ # This checker checks that column has a length constraint if there is a length validation
6
6
  class LengthConstraintChecker < ColumnChecker
7
7
  VALIDATOR_CLASS =
8
8
  if defined?(ActiveRecord::Validations::LengthValidator)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module DatabaseConsistency
4
4
  module Checkers
5
- # This class checks missing presence validator
5
+ # This class checks that primary key is bigserial, bigint, or uuid
6
6
  class PrimaryKeyTypeChecker < ColumnChecker
7
7
  Report = ReportBuilder.define(
8
8
  DatabaseConsistency::Report,
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DatabaseConsistency
4
+ module Checkers
5
+ # This class checks missing NOT NULL constraint for boolean columns
6
+ class ThreeStateBooleanChecker < ColumnChecker
7
+ Report = ReportBuilder.define(
8
+ DatabaseConsistency::Report,
9
+ :table_name,
10
+ :column_name
11
+ )
12
+
13
+ private
14
+
15
+ def preconditions
16
+ column.type == :boolean
17
+ end
18
+
19
+ def check
20
+ if valid?
21
+ report_template(:ok)
22
+ else
23
+ report_template(:fail, error_slug: :three_state_boolean)
24
+ end
25
+ end
26
+
27
+ def report_template(status, error_slug: nil)
28
+ Report.new(
29
+ status: status,
30
+ error_slug: error_slug,
31
+ error_message: nil,
32
+ table_name: model.table_name,
33
+ column_name: column.name,
34
+ **report_attributes
35
+ )
36
+ end
37
+
38
+ # @return [Boolean]
39
+ def valid?
40
+ !column.null
41
+ end
42
+ end
43
+ end
44
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module DatabaseConsistency
4
4
  module Checkers
5
- # The base class for table checkers
5
+ # The base class for index checkers
6
6
  class IndexChecker < BaseChecker
7
7
  attr_reader :model, :index
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module DatabaseConsistency
4
4
  module Checkers
5
- # This class checks redundant database indexes
5
+ # This class checks redundant database unique indexes
6
6
  class RedundantUniqueIndexChecker < IndexChecker
7
7
  Report = ReportBuilder.define(
8
8
  DatabaseConsistency::Report,
@@ -2,7 +2,7 @@
2
2
 
3
3
  module DatabaseConsistency
4
4
  module Checkers
5
- # This class checks if uniqueness validator has unique index in the database
5
+ # This class checks redundant case_sensitive option for uniqueness validation
6
6
  class CaseSensitiveUniqueValidationChecker < ValidatorChecker
7
7
  private
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module DatabaseConsistency
4
4
  module Checkers
5
- # The base class for validator checker
5
+ # The base class for validator fraction checkers
6
6
  class ValidatorsFractionChecker < BaseChecker
7
7
  attr_reader :model, :attribute, :validators
8
8
 
@@ -36,8 +36,8 @@ module DatabaseConsistency
36
36
 
37
37
  # Return list of not inherited models
38
38
  def parent_models
39
- models.group_by(&:table_name).each_value.map do |models|
40
- models.min_by { |model| models.include?(model.superclass) ? 1 : 0 }
39
+ models.group_by(&:table_name).each_value.flat_map do |models|
40
+ models.reject { |model| models.include?(model.superclass) }
41
41
  end
42
42
  end
43
43
 
@@ -8,7 +8,8 @@ module DatabaseConsistency
8
8
  Checkers::NullConstraintChecker,
9
9
  Checkers::LengthConstraintChecker,
10
10
  Checkers::PrimaryKeyTypeChecker,
11
- Checkers::EnumValueChecker
11
+ Checkers::EnumValueChecker,
12
+ Checkers::ThreeStateBooleanChecker
12
13
  ].freeze
13
14
 
14
15
  private
@@ -16,7 +16,7 @@ module DatabaseConsistency
16
16
  end
17
17
 
18
18
  def initialize
19
- puts 'Hey, some of checks fail with an error, please open an issue on github at https://github.com/djezzzl/database_consistency.'
19
+ puts 'Hey, some checks fail with an error, please open an issue on github at https://github.com/djezzzl/database_consistency.'
20
20
  puts "Attach the created file: #{filename}"
21
21
  puts 'Thank you, for your contribution!'
22
22
  puts '(c) Evgeniy Demin <lawliet.djez@gmail.com>'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DatabaseConsistency
4
- VERSION = '1.7.4'
4
+ VERSION = '1.7.6'
5
5
  end
@@ -16,7 +16,8 @@ module DatabaseConsistency
16
16
  null_constraint_missing: Autofix::NullConstraintMissing,
17
17
  redundant_index: Autofix::RedundantIndex,
18
18
  redundant_unique_index: Autofix::RedundantIndex,
19
- small_primary_key: Autofix::InconsistentTypes
19
+ small_primary_key: Autofix::InconsistentTypes,
20
+ three_state_boolean: Autofix::NullConstraintMissing
20
21
  }.freeze
21
22
 
22
23
  def write
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DatabaseConsistency
4
+ module Writers
5
+ module Simple
6
+ class ThreeStateBoolean < Base # :nodoc:
7
+ private
8
+
9
+ def template
10
+ 'boolean column should have NOT NULL constraint'
11
+ end
12
+
13
+ def unique_attributes
14
+ {
15
+ table_name: report.table_name,
16
+ column_name: report.column_name
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -28,7 +28,8 @@ module DatabaseConsistency
28
28
  missing_foreign_key_cascade: Simple::MissingForeignKeyCascade,
29
29
  enum_values_inconsistent_with_ar_enum: Simple::EnumValuesInconsistentWithArEnum,
30
30
  enum_values_inconsistent_with_inclusion: Simple::EnumValuesInconsistentWithInclusion,
31
- redundant_case_insensitive_option: Simple::RedundantCaseInsensitiveOption
31
+ redundant_case_insensitive_option: Simple::RedundantCaseInsensitiveOption,
32
+ three_state_boolean: Simple::ThreeStateBoolean
32
33
  }.freeze
33
34
 
34
35
  def write
@@ -38,6 +38,7 @@ require 'database_consistency/writers/simple/inconsistent_enum_type'
38
38
  require 'database_consistency/writers/simple/enum_values_inconsistent_with_ar_enum'
39
39
  require 'database_consistency/writers/simple/enum_values_inconsistent_with_inclusion'
40
40
  require 'database_consistency/writers/simple/redundant_case_insensitive_option'
41
+ require 'database_consistency/writers/simple/three_state_boolean'
41
42
  require 'database_consistency/writers/simple_writer'
42
43
 
43
44
  require 'database_consistency/writers/autofix/helpers/migration'
@@ -71,6 +72,7 @@ require 'database_consistency/checkers/column_checkers/null_constraint_checker'
71
72
  require 'database_consistency/checkers/column_checkers/length_constraint_checker'
72
73
  require 'database_consistency/checkers/column_checkers/primary_key_type_checker'
73
74
  require 'database_consistency/checkers/column_checkers/enum_value_checker'
75
+ require 'database_consistency/checkers/column_checkers/three_state_boolean_checker'
74
76
 
75
77
  require 'database_consistency/checkers/validator_checkers/validator_checker'
76
78
  require 'database_consistency/checkers/validator_checkers/missing_unique_index_checker'
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.4
4
+ version: 1.7.6
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-01-20 00:00:00.000000000 Z
11
+ date: 2023-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -157,6 +157,7 @@ files:
157
157
  - lib/database_consistency/checkers/column_checkers/length_constraint_checker.rb
158
158
  - lib/database_consistency/checkers/column_checkers/null_constraint_checker.rb
159
159
  - lib/database_consistency/checkers/column_checkers/primary_key_type_checker.rb
160
+ - lib/database_consistency/checkers/column_checkers/three_state_boolean_checker.rb
160
161
  - lib/database_consistency/checkers/enum_checkers/enum_checker.rb
161
162
  - lib/database_consistency/checkers/enum_checkers/enum_type_checker.rb
162
163
  - lib/database_consistency/checkers/index_checkers/index_checker.rb
@@ -228,6 +229,7 @@ files:
228
229
  - lib/database_consistency/writers/simple/redundant_index.rb
229
230
  - lib/database_consistency/writers/simple/redundant_unique_index.rb
230
231
  - lib/database_consistency/writers/simple/small_primary_key.rb
232
+ - lib/database_consistency/writers/simple/three_state_boolean.rb
231
233
  - lib/database_consistency/writers/simple_writer.rb
232
234
  - lib/database_consistency/writers/todo_writer.rb
233
235
  homepage: https://github.com/djezzzl/database_consistency
@@ -262,7 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
262
264
  - !ruby/object:Gem::Version
263
265
  version: '0'
264
266
  requirements: []
265
- rubygems_version: 3.2.33
267
+ rubygems_version: 3.1.6
266
268
  signing_key:
267
269
  specification_version: 4
268
270
  summary: Provide an easy way to check the consistency of the database constraints