database_consistency 1.3.5 → 1.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (25) hide show
  1. checksums.yaml +4 -4
  2. data/lib/database_consistency/version.rb +1 -1
  3. data/lib/database_consistency/writers/autofix_writer.rb +2 -2
  4. data/lib/database_consistency/writers/simple/association_missing_index.rb +22 -0
  5. data/lib/database_consistency/writers/simple/association_missing_null_constraint.rb +22 -0
  6. data/lib/database_consistency/writers/simple/base.rb +8 -0
  7. data/lib/database_consistency/writers/simple/error_message.rb +7 -0
  8. data/lib/database_consistency/writers/simple/has_one_missing_unique_index.rb +23 -0
  9. data/lib/database_consistency/writers/simple/inconsistent_types.rb +8 -0
  10. data/lib/database_consistency/writers/simple/length_validator_greater_limit.rb +22 -0
  11. data/lib/database_consistency/writers/simple/length_validator_lower_limit.rb +22 -0
  12. data/lib/database_consistency/writers/simple/length_validator_missing.rb +22 -0
  13. data/lib/database_consistency/writers/simple/missing_foreign_key.rb +24 -0
  14. data/lib/database_consistency/writers/simple/missing_unique_index.rb +23 -0
  15. data/lib/database_consistency/writers/simple/missing_uniqueness_validation.rb +22 -0
  16. data/lib/database_consistency/writers/simple/null_constraint_association_misses_validator.rb +7 -0
  17. data/lib/database_consistency/writers/simple/null_constraint_misses_validator.rb +22 -0
  18. data/lib/database_consistency/writers/simple/null_constraint_missing.rb +22 -0
  19. data/lib/database_consistency/writers/simple/possible_null.rb +22 -0
  20. data/lib/database_consistency/writers/simple/redundant_index.rb +6 -0
  21. data/lib/database_consistency/writers/simple/redundant_unique_index.rb +6 -0
  22. data/lib/database_consistency/writers/simple/small_primary_key.rb +22 -0
  23. data/lib/database_consistency/writers/simple_writer.rb +19 -20
  24. data/lib/database_consistency.rb +13 -0
  25. metadata +15 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f935ca51faca06dad689d217e897a035253f4ce9884f1826befdf1bcbbee3b5
4
- data.tar.gz: 38bde32ffee8b05b04bc8a1af261764f967b64f322352ef8d79729f1de485e13
3
+ metadata.gz: ad00c3759184fa0098812d4cb79169f109205bff2861c37965d56c42c4da568f
4
+ data.tar.gz: 579087c2a52d57bac85af5fc7f9e86fa31b6c78bbaab1583128e319f9156dafb
5
5
  SHA512:
6
- metadata.gz: 2352fa358c91e6dbec9a22c9abac34fb27b45e662c1402e88cfe94864b7bfa4966628f246a6f6f5d6c6af323e1320a3fe03c74df644f86ec6d14e4bde7c81962
7
- data.tar.gz: ad812a3ce4c8d4d0a7d24d9031815a26ae2c32bfca6d0721430f3c31f01d8c5910f4af091fb7d088e4860d65d887ba0a27531bdd0d8aefc50b589a944ef29290
6
+ metadata.gz: 206324a83d7f850bde79bb8a4399362ba7ff4f94cf848139d55781cf7e6f54d8b03d5e4641928193689c0c818c803badbcbb4f72685031f72dab26eea1f4a80a
7
+ data.tar.gz: 2cbaed407b168b1100de5cb6962d2fedac6ce2e8f955a5ed4811ef9d80227a2f3f396de98c9ed0a9de8c5ca751c092f389b482852663a510860cbaad85866643
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DatabaseConsistency
4
- VERSION = '1.3.5'
4
+ VERSION = '1.3.6'
5
5
  end
@@ -41,8 +41,8 @@ module DatabaseConsistency
41
41
  klass&.new(report)
42
42
  end
43
43
 
44
- def unique_key(report)
45
- [report.class, report.attributes]
44
+ def unique_key(generator)
45
+ [generator.class, generator.attributes]
46
46
  end
47
47
  end
48
48
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DatabaseConsistency
4
+ module Writers
5
+ module Simple
6
+ class AssociationMissingIndex < Base # :nodoc:
7
+ private
8
+
9
+ def template
10
+ 'associated model should have proper index in the database'
11
+ end
12
+
13
+ def unique_attributes
14
+ {
15
+ table_name: report.table_name,
16
+ columns: report.columns
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DatabaseConsistency
4
+ module Writers
5
+ module Simple
6
+ class AssociationMissingNullConstraint < Base # :nodoc:
7
+ private
8
+
9
+ def template
10
+ 'association foreign key column should be required in the database'
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
@@ -36,8 +36,16 @@ module DatabaseConsistency
36
36
  "#{report.checker_name} #{status_text} #{key_text} #{message_text}"
37
37
  end
38
38
 
39
+ def unique_key
40
+ { class: self.class }.merge(unique_attributes)
41
+ end
42
+
39
43
  private
40
44
 
45
+ def unique_attributes
46
+ raise StandardError, 'Missing the implementation'
47
+ end
48
+
41
49
  def message_text
42
50
  template % attributes
43
51
  end
@@ -9,6 +9,13 @@ module DatabaseConsistency
9
9
  def template
10
10
  report.error_message || ''
11
11
  end
12
+
13
+ def unique_attributes
14
+ {
15
+ template: template,
16
+ checker_name: report.checker_name
17
+ }
18
+ end
12
19
  end
13
20
  end
14
21
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DatabaseConsistency
4
+ module Writers
5
+ module Simple
6
+ class HasOneMissingUniqueIndex < Base # :nodoc:
7
+ private
8
+
9
+ def template
10
+ 'associated model should have proper unique index in the database'
11
+ end
12
+
13
+ def unique_attributes
14
+ {
15
+ table_name: report.table_name,
16
+ columns: report.columns,
17
+ unique: true
18
+ }
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -18,6 +18,14 @@ module DatabaseConsistency
18
18
  pk_type: report.pk_type
19
19
  }
20
20
  end
21
+
22
+ def unique_attributes
23
+ {
24
+ table_to_change: report.table_to_change,
25
+ type_to_set: report.type_to_set,
26
+ fk_name: report.fk_name
27
+ }
28
+ end
21
29
  end
22
30
  end
23
31
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DatabaseConsistency
4
+ module Writers
5
+ module Simple
6
+ class LengthValidatorGreaterLimit < Base # :nodoc:
7
+ private
8
+
9
+ def template
10
+ 'column has greater limit in the database than in length validator'
11
+ end
12
+
13
+ def unique_attributes
14
+ {
15
+ table_or_model_name: report.table_or_model_name,
16
+ column_or_attribute_name: report.column_or_attribute_name
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DatabaseConsistency
4
+ module Writers
5
+ module Simple
6
+ class LengthValidatorLowerLimit < Base # :nodoc:
7
+ private
8
+
9
+ def template
10
+ 'column has lower limit in the database than in length validator'
11
+ end
12
+
13
+ def unique_attributes
14
+ {
15
+ table_or_model_name: report.table_or_model_name,
16
+ column_or_attribute_name: report.column_or_attribute_name
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DatabaseConsistency
4
+ module Writers
5
+ module Simple
6
+ class LengthValidatorMissing < Base # :nodoc:
7
+ private
8
+
9
+ def template
10
+ 'column has limit in the database but do not have length validator'
11
+ end
12
+
13
+ def unique_attributes
14
+ {
15
+ table_or_model_name: report.table_or_model_name,
16
+ column_or_attribute_name: report.column_or_attribute_name
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DatabaseConsistency
4
+ module Writers
5
+ module Simple
6
+ class MissingForeignKey < Base # :nodoc:
7
+ private
8
+
9
+ def template
10
+ 'should have foreign key in the database'
11
+ end
12
+
13
+ def unique_attributes
14
+ {
15
+ foreign_table: report.foreign_table,
16
+ foreign_key: report.foreign_key,
17
+ primary_table: report.primary_table,
18
+ primary_key: report.primary_key
19
+ }
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DatabaseConsistency
4
+ module Writers
5
+ module Simple
6
+ class MissingUniqueIndex < Base # :nodoc:
7
+ private
8
+
9
+ def template
10
+ 'model should have proper unique index in the database'
11
+ end
12
+
13
+ def unique_attributes
14
+ {
15
+ table_name: report.table_name,
16
+ columns: report.columns,
17
+ unique: true
18
+ }
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DatabaseConsistency
4
+ module Writers
5
+ module Simple
6
+ class MissingUniquenessValidation < Base # :nodoc:
7
+ private
8
+
9
+ def template
10
+ 'index is unique in the database but do not have uniqueness validator'
11
+ end
12
+
13
+ def unique_attributes
14
+ {
15
+ table_or_model_name: report.table_or_model_name,
16
+ column_or_attribute_name: report.column_or_attribute_name
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -15,6 +15,13 @@ module DatabaseConsistency
15
15
  association_name: report.association_name
16
16
  }
17
17
  end
18
+
19
+ def unique_attributes
20
+ {
21
+ table_or_model_name: report.table_or_model_name,
22
+ column_or_attribute_name: report.column_or_attribute_name
23
+ }
24
+ end
18
25
  end
19
26
  end
20
27
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DatabaseConsistency
4
+ module Writers
5
+ module Simple
6
+ class NullConstraintMissesValidator < Base # :nodoc:
7
+ private
8
+
9
+ def template
10
+ 'column is required in the database but do not have presence validator'
11
+ end
12
+
13
+ def unique_attributes
14
+ {
15
+ table_or_model_name: report.table_or_model_name,
16
+ column_or_attribute_name: report.column_or_attribute_name
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DatabaseConsistency
4
+ module Writers
5
+ module Simple
6
+ class NullConstraintMissing < Base # :nodoc:
7
+ private
8
+
9
+ def template
10
+ 'column should be required in the database'
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
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DatabaseConsistency
4
+ module Writers
5
+ module Simple
6
+ class PossibleNull < Base # :nodoc:
7
+ private
8
+
9
+ def template
10
+ 'column is required but there is possible null value insert'
11
+ end
12
+
13
+ def unique_attributes
14
+ {
15
+ table_or_model_name: report.table_or_model_name,
16
+ column_or_attribute_name: report.column_or_attribute_name
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -15,6 +15,12 @@ module DatabaseConsistency
15
15
  covered_index_name: report.covered_index_name
16
16
  }
17
17
  end
18
+
19
+ def unique_attributes
20
+ {
21
+ index_name: report.index_name
22
+ }
23
+ end
18
24
  end
19
25
  end
20
26
  end
@@ -15,6 +15,12 @@ module DatabaseConsistency
15
15
  covered_index_name: report.covered_index_name
16
16
  }
17
17
  end
18
+
19
+ def unique_attributes
20
+ {
21
+ index_name: report.index_name
22
+ }
23
+ end
18
24
  end
19
25
  end
20
26
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DatabaseConsistency
4
+ module Writers
5
+ module Simple
6
+ class SmallPrimaryKey < Base # :nodoc:
7
+ private
8
+
9
+ def template
10
+ 'column has int/serial type but recommended to have bigint/bigserial/uuid'
11
+ end
12
+
13
+ def unique_attributes
14
+ {
15
+ table_or_model_name: report.table_or_model_name,
16
+ column_or_attribute_name: report.column_or_attribute_name
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -6,39 +6,38 @@ module DatabaseConsistency
6
6
  # The simplest formatter
7
7
  class SimpleWriter < BaseWriter
8
8
  SLUG_TO_WRITER = {
9
- association_missing_index: Simple::Base.with('associated model should have proper index in the database'),
10
- association_missing_null_constraint: Simple::Base.with('association foreign key column should be required in the database'), # rubocop:disable Layout/LineLength
11
- has_one_missing_unique_index: Simple::Base.with('associated model should have proper unique index in the database'), # rubocop:disable Layout/LineLength
9
+ association_missing_index: Simple::AssociationMissingIndex,
10
+ association_missing_null_constraint: Simple::AssociationMissingNullConstraint,
11
+ has_one_missing_unique_index: Simple::HasOneMissingUniqueIndex,
12
12
  inconsistent_types: Simple::InconsistentTypes,
13
- length_validator_greater_limit: Simple::Base.with('column has greater limit in the database than in length validator'), # rubocop:disable Layout/LineLength
14
- length_validator_lower_limit: Simple::Base.with('column has lower limit in the database than in length validator'), # rubocop:disable Layout/LineLength
15
- length_validator_missing: Simple::Base.with('column has limit in the database but do not have length validator'), # rubocop:disable Layout/LineLength
16
- missing_foreign_key: Simple::Base.with('should have foreign key in the database'),
17
- missing_unique_index: Simple::Base.with('model should have proper unique index in the database'),
18
- missing_uniqueness_validation: Simple::Base.with('index is unique in the database but do not have uniqueness validator'), # rubocop:disable Layout/LineLength
13
+ length_validator_greater_limit: Simple::LengthValidatorGreaterLimit,
14
+ length_validator_lower_limit: Simple::LengthValidatorLowerLimit,
15
+ length_validator_missing: Simple::LengthValidatorMissing,
16
+ missing_foreign_key: Simple::MissingForeignKey,
17
+ missing_unique_index: Simple::MissingUniqueIndex,
18
+ missing_uniqueness_validation: Simple::MissingUniquenessValidation,
19
19
  null_constraint_association_misses_validator: Simple::NullConstraintAssociationMissesValidator,
20
- null_constraint_misses_validator: Simple::Base.with('column is required in the database but do not have presence validator'), # rubocop:disable Layout/LineLength
21
- null_constraint_missing: Simple::Base.with('column should be required in the database'),
22
- possible_null: Simple::Base.with('column is required but there is possible null value insert'),
20
+ null_constraint_misses_validator: Simple::NullConstraintMissesValidator,
21
+ null_constraint_missing: Simple::NullConstraintMissing,
22
+ possible_null: Simple::PossibleNull,
23
23
  redundant_index: Simple::RedundantIndex,
24
24
  redundant_unique_index: Simple::RedundantUniqueIndex,
25
- small_primary_key: Simple::Base.with('column has int/serial type but recommended to have bigint/bigserial/uuid')
25
+ small_primary_key: Simple::SmallPrimaryKey
26
26
  }.freeze
27
27
 
28
28
  def write
29
- results.each do |result|
30
- next unless write?(result.status)
31
-
32
- writer = writer(result)
33
-
29
+ results.select(&method(:write?))
30
+ .map(&method(:writer))
31
+ .uniq(&:unique_key)
32
+ .each do |writer|
34
33
  puts writer.msg
35
34
  end
36
35
  end
37
36
 
38
37
  private
39
38
 
40
- def write?(status)
41
- status == :fail || config.debug?
39
+ def write?(report)
40
+ report.status == :fail || config.debug?
42
41
  end
43
42
 
44
43
  def writer(report)
@@ -18,6 +18,19 @@ require 'database_consistency/writers/simple/inconsistent_types'
18
18
  require 'database_consistency/writers/simple/null_constraint_association_misses_validator'
19
19
  require 'database_consistency/writers/simple/redundant_index'
20
20
  require 'database_consistency/writers/simple/redundant_unique_index'
21
+ require 'database_consistency/writers/simple/association_missing_index'
22
+ require 'database_consistency/writers/simple/association_missing_null_constraint'
23
+ require 'database_consistency/writers/simple/has_one_missing_unique_index'
24
+ require 'database_consistency/writers/simple/length_validator_lower_limit'
25
+ require 'database_consistency/writers/simple/length_validator_greater_limit'
26
+ require 'database_consistency/writers/simple/length_validator_missing'
27
+ require 'database_consistency/writers/simple/missing_foreign_key'
28
+ require 'database_consistency/writers/simple/missing_unique_index'
29
+ require 'database_consistency/writers/simple/missing_uniqueness_validation'
30
+ require 'database_consistency/writers/simple/null_constraint_misses_validator'
31
+ require 'database_consistency/writers/simple/null_constraint_missing'
32
+ require 'database_consistency/writers/simple/possible_null'
33
+ require 'database_consistency/writers/simple/small_primary_key'
21
34
  require 'database_consistency/writers/simple_writer'
22
35
 
23
36
  require 'database_consistency/writers/autofix/helpers/migration'
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.3.5
4
+ version: 1.3.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: 2022-11-13 00:00:00.000000000 Z
11
+ date: 2022-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -196,12 +196,25 @@ files:
196
196
  - lib/database_consistency/writers/autofix/templates/redundant_index.tt
197
197
  - lib/database_consistency/writers/autofix_writer.rb
198
198
  - lib/database_consistency/writers/base_writer.rb
199
+ - lib/database_consistency/writers/simple/association_missing_index.rb
200
+ - lib/database_consistency/writers/simple/association_missing_null_constraint.rb
199
201
  - lib/database_consistency/writers/simple/base.rb
200
202
  - lib/database_consistency/writers/simple/error_message.rb
203
+ - lib/database_consistency/writers/simple/has_one_missing_unique_index.rb
201
204
  - lib/database_consistency/writers/simple/inconsistent_types.rb
205
+ - lib/database_consistency/writers/simple/length_validator_greater_limit.rb
206
+ - lib/database_consistency/writers/simple/length_validator_lower_limit.rb
207
+ - lib/database_consistency/writers/simple/length_validator_missing.rb
208
+ - lib/database_consistency/writers/simple/missing_foreign_key.rb
209
+ - lib/database_consistency/writers/simple/missing_unique_index.rb
210
+ - lib/database_consistency/writers/simple/missing_uniqueness_validation.rb
202
211
  - lib/database_consistency/writers/simple/null_constraint_association_misses_validator.rb
212
+ - lib/database_consistency/writers/simple/null_constraint_misses_validator.rb
213
+ - lib/database_consistency/writers/simple/null_constraint_missing.rb
214
+ - lib/database_consistency/writers/simple/possible_null.rb
203
215
  - lib/database_consistency/writers/simple/redundant_index.rb
204
216
  - lib/database_consistency/writers/simple/redundant_unique_index.rb
217
+ - lib/database_consistency/writers/simple/small_primary_key.rb
205
218
  - lib/database_consistency/writers/simple_writer.rb
206
219
  - lib/database_consistency/writers/todo_writer.rb
207
220
  homepage: https://github.com/djezzzl/database_consistency