Skip to content

Use constant to refer to main database name

Patrick Bair requested to merge 343047-remove-hardcoded-database-name into master

What does this MR do and why?

Related to #343047 (closed)

Introduce a constant that defines the default tracking database for background migrations and use it throughout, rather than various different hardcoded values of 'main' or :main.

This is part of the effort to make background migrations work with multiple databases, and so a transitional change to the end state. Once we have wired up the migration helpers to use the target database of the migration as the tracking database, we can remove the default database altogether and rely solely on the worker definition of their tracking databases.

How to set up and validate locally

The intent of this MR is to keep the current behavior the same, so we can directly exercise the worker to ensure it runs the job:

  1. Setup some test migration job class:

    module Gitlab
      module BackgroundMigration
        class MyTestJob
          def perform(*args)
            puts "args: #{args}"
          end
        end
      end
    end
  2. Run the job inline with the existing worker:

    BackgroundMigrationWorker.new.perform('MyTestJob', [10, 20])
  3. Verify the output looks similar to:

    args: [10, 20]
  4. Schedule the job to run at a later time:

    BackgroundMigrationWorker.perform_in(1.week, 'MyTestJob', [20, 30])
  5. Force the job to run now anyhow:

    Gitlab::BackgroundMigration.steal('MyTestJob')
  6. Verify the output looks similar to:

    args: [20, 30]

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Patrick Bair

Merge request reports