Improve Migrations handling

DB Migrations are difficult to manage. There's three databases that migrations can run against - GitLab, Praefect and Geo Tracking - Where the process differs along with the hard requirement that migrations need to run directly against the database and bypass PgBouncer.

In practice then this requires the following flow:

  • Update gitlab.rb with database settings that point directly to the database and skip PgBouncer (if PgBouncer is being used) and to temporarily set gitlab_rails['auto_migrate'] / praefect['auto_migrate'] / geo_secondary['auto_migrate'] to true.
  • Run reconfigure to propagate config and run migrations.
    • There is gitlab-ctl gitlab:db:configure available for GitLab only as a specific command but reconfigure is required anyways to propagate config. The same is the case for Geo with db:migrate:geo. There is no specific command for Praefect (raised separately).
  • Update gitlab.rb settings to point to PgBouncer again and set gitlab_rails['auto_migrate'] / praefect['auto_migrate'] / geo_secondary['auto_migrate'] to false.
  • Run reconfigure again to propagate config.

This is quite a complex flow to run DB migrations and is prone to user error. It's also difficult to automate. This should be improved.

Some ideas:

  • Have a migrations command for GitLab, Praefect and Geo Tracking that accepts config directly to run migrations (direct db connection details, etc...)
  • Add new config that users can configure with the direct Database connection details for migrations and have a migrations command for GitLab, Praefect and Geo Tracking that follows that config
  • Add a failsafe check in the process to detect if migrations are running through PgBouncer in error to prevent this from happening
Edited Nov 23, 2023 by Grant Young
Assignee Loading
Time tracking Loading