database_consistency 1.7.16 → 1.7.18
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 +4 -4
- data/lib/database_consistency/checkers/association_checkers/missing_association_class_checker.rb +7 -1
- data/lib/database_consistency/checkers/column_checkers/implicit_ordering_checker.rb +48 -0
- data/lib/database_consistency/processors/columns_processor.rb +2 -1
- data/lib/database_consistency/report_builder.rb +1 -1
- data/lib/database_consistency/version.rb +1 -1
- data/lib/database_consistency/writers/simple/implicit_order_column_missing.rb +22 -0
- data/lib/database_consistency/writers/simple/missing_association_class.rb +1 -1
- data/lib/database_consistency/writers/simple_writer.rb +1 -0
- data/lib/database_consistency.rb +2 -0
- metadata +4 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 83e68ed4220ec40c55d0e018d8b99da78f98354b9e550279dba9fda64859e011
         | 
| 4 | 
            +
              data.tar.gz: d729674e108e0051fc41dec2aa92dbe05d645b9b7c0f6fc6f87fb3a61ab2c94e
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: a87472873c4cfbfd797742a24229ef01693d610f78db20f15e012779e182bcaf5626743ee85b117bcda95289cf8155cf30a5c13f285b4a68373443a22b2bcc85
         | 
| 7 | 
            +
              data.tar.gz: 8c52b06123f13a5932c3069e6a5cfb609a5008b8622eab6755d04661fd99b3e31482a91b575c760ab6f8f10013364e91eb9d9504df8c2e9b088194de235890d9
         | 
    
        data/lib/database_consistency/checkers/association_checkers/missing_association_class_checker.rb
    CHANGED
    
    | @@ -27,10 +27,16 @@ module DatabaseConsistency | |
| 27 27 | 
             
                      status: status,
         | 
| 28 28 | 
             
                      error_message: nil,
         | 
| 29 29 | 
             
                      error_slug: error_slug,
         | 
| 30 | 
            -
                      class_name:  | 
| 30 | 
            +
                      class_name: class_name,
         | 
| 31 31 | 
             
                      **report_attributes
         | 
| 32 32 | 
             
                    )
         | 
| 33 33 | 
             
                  end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                  def class_name
         | 
| 36 | 
            +
                    association.class_name
         | 
| 37 | 
            +
                  rescue NoMethodError
         | 
| 38 | 
            +
                    nil
         | 
| 39 | 
            +
                  end
         | 
| 34 40 | 
             
                end
         | 
| 35 41 | 
             
              end
         | 
| 36 42 | 
             
            end
         | 
| @@ -0,0 +1,48 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module DatabaseConsistency
         | 
| 4 | 
            +
              module Checkers
         | 
| 5 | 
            +
                # This class checks that primary column type is "uuid" and the model class defines `self.implicit_order_column`
         | 
| 6 | 
            +
                class ImplicitOrderingChecker < ColumnChecker
         | 
| 7 | 
            +
                  Report = ReportBuilder.define(DatabaseConsistency::Report)
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  private
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  TARGET_COLUMN_TYPE = 'uuid'
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  # We skip check when:
         | 
| 14 | 
            +
                  # - adapter is not PostgreSQL
         | 
| 15 | 
            +
                  # - column is not a primary key
         | 
| 16 | 
            +
                  # - column type is not "uuid"
         | 
| 17 | 
            +
                  def preconditions
         | 
| 18 | 
            +
                    ActiveRecord::VERSION::MAJOR >= 6 &&
         | 
| 19 | 
            +
                      Helper.postgresql? &&
         | 
| 20 | 
            +
                      primary_field? &&
         | 
| 21 | 
            +
                      column.sql_type.to_s.match(TARGET_COLUMN_TYPE)
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  # Table of possible statuses
         | 
| 25 | 
            +
                  # | defined `self.implicit_order_column` | status |
         | 
| 26 | 
            +
                  # | ----------------------------------- | ------ |
         | 
| 27 | 
            +
                  # | yes                                 | ok     |
         | 
| 28 | 
            +
                  # | no                                  | fail   |
         | 
| 29 | 
            +
                  def check
         | 
| 30 | 
            +
                    if implicit_order_column_defined?
         | 
| 31 | 
            +
                      report_template(:ok)
         | 
| 32 | 
            +
                    else
         | 
| 33 | 
            +
                      report_template(:fail, error_slug: :implicit_order_column_missing)
         | 
| 34 | 
            +
                    end
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  # @return [Boolean]
         | 
| 38 | 
            +
                  def primary_field?
         | 
| 39 | 
            +
                    column.name.to_s == model.primary_key.to_s
         | 
| 40 | 
            +
                  end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                  # @return [Boolean]
         | 
| 43 | 
            +
                  def implicit_order_column_defined?
         | 
| 44 | 
            +
                    model.implicit_order_column.present?
         | 
| 45 | 
            +
                  end
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
            end
         | 
| @@ -9,7 +9,8 @@ module DatabaseConsistency | |
| 9 9 | 
             
                    Checkers::LengthConstraintChecker,
         | 
| 10 10 | 
             
                    Checkers::PrimaryKeyTypeChecker,
         | 
| 11 11 | 
             
                    Checkers::EnumValueChecker,
         | 
| 12 | 
            -
                    Checkers::ThreeStateBooleanChecker
         | 
| 12 | 
            +
                    Checkers::ThreeStateBooleanChecker,
         | 
| 13 | 
            +
                    Checkers::ImplicitOrderingChecker
         | 
| 13 14 | 
             
                  ].freeze
         | 
| 14 15 |  | 
| 15 16 | 
             
                  private
         | 
| @@ -7,7 +7,7 @@ module DatabaseConsistency | |
| 7 7 | 
             
                    attr_reader(*attrs)
         | 
| 8 8 |  | 
| 9 9 | 
             
                    class_eval(<<~DEF, __FILE__, __LINE__ + 1)
         | 
| 10 | 
            -
                      def initialize(#{attrs.map { |attr| "#{attr}:" }.join(', ')}, **opts)
         | 
| 10 | 
            +
                      def initialize(#{attrs.map { |attr| "#{attr}:" }.join(', ')}#{"," if attrs.any?} **opts)
         | 
| 11 11 | 
             
                        super(**opts) if opts.any?
         | 
| 12 12 | 
             
                        #{attrs.map { |attr| "@#{attr} = #{attr}" }.join("\n")}
         | 
| 13 13 | 
             
                      end
         | 
| @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module DatabaseConsistency
         | 
| 4 | 
            +
              module Writers
         | 
| 5 | 
            +
                module Simple
         | 
| 6 | 
            +
                  class ImplicitOrderColumnMissing < Base # :nodoc:
         | 
| 7 | 
            +
                    private
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                    def template
         | 
| 10 | 
            +
                      'implicit_order_column is recommended when using uuid column type for primary key'
         | 
| 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
         | 
| @@ -12,6 +12,7 @@ module DatabaseConsistency | |
| 12 12 | 
             
                    enum_values_inconsistent_with_ar_enum: Simple::EnumValuesInconsistentWithArEnum,
         | 
| 13 13 | 
             
                    enum_values_inconsistent_with_inclusion: Simple::EnumValuesInconsistentWithInclusion,
         | 
| 14 14 | 
             
                    has_one_missing_unique_index: Simple::HasOneMissingUniqueIndex,
         | 
| 15 | 
            +
                    implicit_order_column_missing: Simple::ImplicitOrderColumnMissing,
         | 
| 15 16 | 
             
                    inconsistent_enum_type: Simple::InconsistentEnumType,
         | 
| 16 17 | 
             
                    inconsistent_types: Simple::InconsistentTypes,
         | 
| 17 18 | 
             
                    length_validator_greater_limit: Simple::LengthValidatorGreaterLimit,
         | 
    
        data/lib/database_consistency.rb
    CHANGED
    
    | @@ -42,6 +42,7 @@ require 'database_consistency/writers/simple/redundant_case_insensitive_option' | |
| 42 42 | 
             
            require 'database_consistency/writers/simple/three_state_boolean'
         | 
| 43 43 | 
             
            require 'database_consistency/writers/simple/missing_association_class'
         | 
| 44 44 | 
             
            require 'database_consistency/writers/simple/missing_table'
         | 
| 45 | 
            +
            require 'database_consistency/writers/simple/implicit_order_column_missing'
         | 
| 45 46 | 
             
            require 'database_consistency/writers/simple_writer'
         | 
| 46 47 |  | 
| 47 48 | 
             
            require 'database_consistency/writers/autofix/helpers/migration'
         | 
| @@ -80,6 +81,7 @@ require 'database_consistency/checkers/column_checkers/length_constraint_checker | |
| 80 81 | 
             
            require 'database_consistency/checkers/column_checkers/primary_key_type_checker'
         | 
| 81 82 | 
             
            require 'database_consistency/checkers/column_checkers/enum_value_checker'
         | 
| 82 83 | 
             
            require 'database_consistency/checkers/column_checkers/three_state_boolean_checker'
         | 
| 84 | 
            +
            require 'database_consistency/checkers/column_checkers/implicit_ordering_checker.rb'
         | 
| 83 85 |  | 
| 84 86 | 
             
            require 'database_consistency/checkers/validator_checkers/validator_checker'
         | 
| 85 87 | 
             
            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 | 
            +
              version: 1.7.18
         | 
| 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-07- | 
| 11 | 
            +
            date: 2023-07-22 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activerecord
         | 
| @@ -155,6 +155,7 @@ files: | |
| 155 155 | 
             
            - lib/database_consistency/checkers/base_checker.rb
         | 
| 156 156 | 
             
            - lib/database_consistency/checkers/column_checkers/column_checker.rb
         | 
| 157 157 | 
             
            - lib/database_consistency/checkers/column_checkers/enum_value_checker.rb
         | 
| 158 | 
            +
            - lib/database_consistency/checkers/column_checkers/implicit_ordering_checker.rb
         | 
| 158 159 | 
             
            - lib/database_consistency/checkers/column_checkers/length_constraint_checker.rb
         | 
| 159 160 | 
             
            - lib/database_consistency/checkers/column_checkers/null_constraint_checker.rb
         | 
| 160 161 | 
             
            - lib/database_consistency/checkers/column_checkers/primary_key_type_checker.rb
         | 
| @@ -217,6 +218,7 @@ files: | |
| 217 218 | 
             
            - lib/database_consistency/writers/simple/enum_values_inconsistent_with_ar_enum.rb
         | 
| 218 219 | 
             
            - lib/database_consistency/writers/simple/enum_values_inconsistent_with_inclusion.rb
         | 
| 219 220 | 
             
            - lib/database_consistency/writers/simple/has_one_missing_unique_index.rb
         | 
| 221 | 
            +
            - lib/database_consistency/writers/simple/implicit_order_column_missing.rb
         | 
| 220 222 | 
             
            - lib/database_consistency/writers/simple/inconsistent_enum_type.rb
         | 
| 221 223 | 
             
            - lib/database_consistency/writers/simple/inconsistent_types.rb
         | 
| 222 224 | 
             
            - lib/database_consistency/writers/simple/length_validator_greater_limit.rb
         |