Skip to content

Use Backup::DatabaseConnection if configured

What does this MR do and why?

Use Backup::DatabaseConnection if configured

If user runs the db rake task with ENV config for direct connection to Postgres, then use it with Backup::DatabaseConnection.

References

How to set up and validate locally

  1. Checkout this MR

  2. Run the task: bin/rails gitlab:db:collation_checker:main, it should run without error

  3. Run the task again with correct ENV variable set:

    $ GITLAB_BACKUP_PGUSER=bishwa bin/rails gitlab:db:collation_checker:main
    I, [2025-08-21T18:09:26.787652 #90125]  INFO -- : Checking for PostgreSQL collation mismatches on main database...
    I, [2025-08-21T18:09:26.792673 #90125]  INFO -- : No collation version mismatches detected on main.
    I, [2025-08-21T18:09:26.792692 #90125]  INFO -- : Found 8 indexes to corruption spot check.
    I, [2025-08-21T18:09:26.839257 #90125]  INFO -- : No corrupted indexes detected.
  4. To test that it respects the ENV variable, set the wrong value and assert that it fails

    $ GITLAB_BACKUP_PGUSER=foobar bin/rails gitlab:db:collation_checker:main
    I, [2025-08-21T18:10:19.240188 #90201]  INFO -- : Checking for PostgreSQL collation mismatches on main database...
    bin/rails aborted!
    ActiveRecord::DatabaseConnectionError: There is an issue connecting to your database with your username/password, username: foobar.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #562640 (closed)

Edited by Bishwa Hang Rai

Merge request reports

Loading