gitlabhq/gitlabhq

View on GitHub
lib/gitlab/database/migration_helpers.rb

Summary

Maintainability
F
3 days
Test Coverage

File migration_helpers.rb has 548 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module Gitlab
  module Database
    module MigrationHelpers
      BACKGROUND_MIGRATION_BATCH_SIZE = 1000 # Number of rows to process per job
      BACKGROUND_MIGRATION_JOB_BUFFER_SIZE = 1000 # Number of jobs to bulk queue at a time
Severity: Major
Found in lib/gitlab/database/migration_helpers.rb - About 1 day to fix

    Method copy_indexes has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

          def copy_indexes(table, old, new)
            old = old.to_s
            new = new.to_s
    
            indexes_for(table, old).each do |index|
    Severity: Minor
    Found in lib/gitlab/database/migration_helpers.rb - About 2 hrs to fix

    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 update_column_in_batches has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

          def update_column_in_batches(table, column, value, batch_size: nil)
            if transaction_open?
              raise 'update_column_in_batches can not be run inside a transaction, ' \
                'you can disable transactions by calling disable_ddl_transaction! ' \
                'in the body of your migration class'
    Severity: Minor
    Found in lib/gitlab/database/migration_helpers.rb - About 2 hrs to fix

    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 update_column_in_batches has 39 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def update_column_in_batches(table, column, value, batch_size: nil)
            if transaction_open?
              raise 'update_column_in_batches can not be run inside a transaction, ' \
                'you can disable transactions by calling disable_ddl_transaction! ' \
                'in the body of your migration class'
    Severity: Minor
    Found in lib/gitlab/database/migration_helpers.rb - About 1 hr to fix

      Method add_concurrent_foreign_key has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def add_concurrent_foreign_key(source, target, column:, on_delete: :cascade)
              # Transactions would result in ALTER TABLE locks being held for the
              # duration of the transaction, defeating the purpose of this method.
              if transaction_open?
                raise 'add_concurrent_foreign_key can not be run inside a transaction'
      Severity: Minor
      Found in lib/gitlab/database/migration_helpers.rb - About 1 hr to fix

        Method rename_column_using_background_migration has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def rename_column_using_background_migration(
                table,
                old_column,
                new_column,
                type: nil,
        Severity: Minor
        Found in lib/gitlab/database/migration_helpers.rb - About 1 hr to fix

          Method add_concurrent_foreign_key has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

                def add_concurrent_foreign_key(source, target, column:, on_delete: :cascade)
                  # Transactions would result in ALTER TABLE locks being held for the
                  # duration of the transaction, defeating the purpose of this method.
                  if transaction_open?
                    raise 'add_concurrent_foreign_key can not be run inside a transaction'
          Severity: Minor
          Found in lib/gitlab/database/migration_helpers.rb - About 1 hr to fix

          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 add_column_with_default has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

                def add_column_with_default(table, column, type, default:, limit: nil, allow_null: false, &block)
                  if transaction_open?
                    raise 'add_column_with_default can not be run inside a transaction, ' \
                      'you can disable transactions by calling disable_ddl_transaction! ' \
                      'in the body of your migration class'
          Severity: Minor
          Found in lib/gitlab/database/migration_helpers.rb - About 1 hr to fix

          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_type_using_background_migration has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def change_column_type_using_background_migration(
                  relation,
                  column,
                  new_type,
                  batch_size: 10_000,
          Severity: Minor
          Found in lib/gitlab/database/migration_helpers.rb - About 1 hr to fix

            Method copy_indexes has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  def copy_indexes(table, old, new)
                    old = old.to_s
                    new = new.to_s
            
                    indexes_for(table, old).each do |index|
            Severity: Minor
            Found in lib/gitlab/database/migration_helpers.rb - About 1 hr to fix

              Method disable_statement_timeout has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                    def disable_statement_timeout
                      # bypass disabled_statement logic when not using postgres, but still execute block when one is given
                      unless Database.postgresql?
                        if block_given?
                          yield
              Severity: Minor
              Found in lib/gitlab/database/migration_helpers.rb - About 55 mins to fix

              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 add_timestamps_with_timezone has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                    def add_timestamps_with_timezone(table_name, options = {})
                      options[:null] = false if options[:null].nil?
              
                      [:created_at, :updated_at].each do |column_name|
                        if options[:default] && transaction_open?
              Severity: Minor
              Found in lib/gitlab/database/migration_helpers.rb - About 35 mins to fix

              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 bulk_queue_background_migration_jobs_by_range has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                    def bulk_queue_background_migration_jobs_by_range(model_class, job_class_name, batch_size: BACKGROUND_MIGRATION_BATCH_SIZE)
                      raise "#{model_class} does not have an ID to use for batch ranges" unless model_class.column_names.include?('id')
              
                      jobs = []
                      table_name = model_class.quoted_table_name
              Severity: Minor
              Found in lib/gitlab/database/migration_helpers.rb - About 25 mins to fix

              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

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                      model.where.not(old_column => nil).each_batch(of: batch_size) do |batch, index|
                        start_id, end_id = batch.pluck('MIN(id), MAX(id)').first
                        max_index = index
              
                        BackgroundMigrationWorker.perform_in(
              Severity: Minor
              Found in lib/gitlab/database/migration_helpers.rb and 1 other location - About 35 mins to fix
              lib/gitlab/database/migration_helpers.rb on lines 618..625

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 36.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                      relation.where.not(column => nil).each_batch(of: batch_size) do |batch, index|
                        start_id, end_id = batch.pluck('MIN(id), MAX(id)').first
                        max_index = index
              
                        BackgroundMigrationWorker.perform_in(
              Severity: Minor
              Found in lib/gitlab/database/migration_helpers.rb and 1 other location - About 35 mins to fix
              lib/gitlab/database/migration_helpers.rb on lines 709..716

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 36.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              There are no issues that match your filters.

              Category
              Status