Add rake task to wait for batched background migrations to finish
What does this MR do and why?
Adds a gitlab:background_migrations:wait rake task that blocks until all batched background migrations across every database have finished.
Batched background migrations are enqueued from post-deployment migrations and run asynchronously, so the migrations completing does not mean the BBMs are done. Starting the next upgrade while they are still running risks data inconsistency. This task gives a reliable way to wait for them to drain before proceeding.
It polls BatchedMigration.unfinished on each database and:
- exits 0 once none remain,
- exits 1 (listing the offending migrations) if any are in the terminal failed state, since a wait cannot clear those — they need manual finalization.
The poll interval defaults to 30s and is configurable via BATCHED_MIGRATIONS_WAIT_INTERVAL_SECONDS. The task has no internal timeout by design: the caller (e.g. the wait Job the GitLab chart renders during a zero-downtime upgrade) bounds the total runtime and retries on transient database errors.
This replaces a standalone toolbox script in Cloud Native GitLab that reimplemented the same logic in an inline Ruby snippet. Keeping the logic here means it lives alongside the internals it depends on and is covered by CI, rather than breaking silently if those APIs change.
References
- Charts MR: gitlab-org/charts/gitlab!5372
- Operator MR: gitlab-org/cloud-native/gitlab-operator!1700
Screenshots or screen recordings
| Before | After |
|---|---|
How to set up and validate locally
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.