activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb

Summary

Maintainability
F
3 days
Test Coverage

File schema_statements.rb has 791 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module ActiveRecord
  module ConnectionAdapters
    module PostgreSQL
      module SchemaStatements
        # Drops the database specified on the +name+ attribute

    Method reset_pk_sequence! has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

            def reset_pk_sequence!(table, pk = nil, sequence = nil) # :nodoc:
              unless pk && sequence
                default_pk, default_sequence = pk_and_sequence_for(table)
    
                pk ||= default_pk

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method indexes has 55 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            def indexes(table_name) # :nodoc:
              scope = quoted_scope(table_name)
    
              result = query(<<~SQL, "SCHEMA")
                SELECT distinct i.relname, d.indisunique, d.indkey, pg_get_indexdef(d.indexrelid), t.oid,

      Method indexes has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

              def indexes(table_name) # :nodoc:
                scope = quoted_scope(table_name)
      
                result = query(<<~SQL, "SCHEMA")
                  SELECT distinct i.relname, d.indisunique, d.indkey, pg_get_indexdef(d.indexrelid), t.oid,

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method pk_and_sequence_for has 46 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              def pk_and_sequence_for(table) # :nodoc:
                # First try looking for a sequence with a dependency on the
                # given table's primary key.
                result = query(<<~SQL, "SCHEMA")[0]
                  SELECT attr.attname, nsp.nspname, seq.relname

        Method foreign_keys has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                def foreign_keys(table_name)
                  scope = quoted_scope(table_name)
                  fk_info = internal_exec_query(<<~SQL, "SCHEMA", allow_retry: true, materialize_transactions: false)
                    SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete, c.convalidated AS valid, c.condeferrable AS deferrable, c.condeferred AS deferred, c.conkey, c.confkey, c.conrelid, c.confrelid
                    FROM pg_constraint c

          Method type_to_sql has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

                  def type_to_sql(type, limit: nil, precision: nil, scale: nil, array: nil, enum_type: nil, **) # :nodoc:
                    sql = \
                      case type.to_s
                      when "binary"
                        # PostgreSQL doesn't support limits on binary (bytea) columns.

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Method type_to_sql has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  def type_to_sql(type, limit: nil, precision: nil, scale: nil, array: nil, enum_type: nil, **) # :nodoc:
                    sql = \
                      case type.to_s
                      when "binary"
                        # PostgreSQL doesn't support limits on binary (bytea) columns.

            Method remove_index has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                    def remove_index(table_name, column_name = nil, **options) # :nodoc:
                      table = Utils.extract_schema_qualified_name(table_name.to_s)
            
                      if options.key?(:name)
                        provided_index = Utils.extract_schema_qualified_name(options[:name].to_s)

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method change_column_null has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                    def change_column_null(table_name, column_name, null, default = nil) # :nodoc:
                      validate_change_column_null_argument!(null)
            
                      clear_cache!
                      unless null || default.nil?

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method pk_and_sequence_for has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                    def pk_and_sequence_for(table) # :nodoc:
                      # First try looking for a sequence with a dependency on the
                      # given table's primary key.
                      result = query(<<~SQL, "SCHEMA")[0]
                        SELECT attr.attname, nsp.nspname, seq.relname

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method rename_table has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                    def rename_table(table_name, new_name, **options)
                      validate_table_length!(new_name) unless options[:_uses_legacy_table_name]
                      clear_cache!
                      schema_cache.clear_data_source_cache!(table_name.to_s)
                      schema_cache.clear_data_source_cache!(new_name.to_s)

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            There are no issues that match your filters.

            Category
            Status