Fix hosted_plan_name_uid for gitlab_subscriptions
What does this MR do and why?
This MR introduces a batched background migration to fix hosted_plan_name_uid values
in the gitlab_subscriptions table that became out of sync due to a deployment gap.
The previous backfill migration (BackfillGitlabSubscriptionsHostedPlanNameUid, queued
in 20260115114900) was finalized in !231589 (merged), but a deployment issue left some rows with
hosted_plan_name_uid values that do not match the corresponding plans.plan_name_uid.
This migration corrects those 2193 rows by re-syncing hosted_plan_name_uid from the plans
table for any subscription where the values are mismatched or NULL.
This is part of the broader effort to make hosted_plan_name_uid the source of truth for
plan associations in gitlab_subscriptions, removing the dependency on the plans table's
id column.
Query plan
I used a subquery to get 1000 subscription ids but in practice those would be substituted in as a list before the query hits the DB.
https://console.postgres.ai/gitlab/gitlab-production-main/sessions/51488/commands/152148
References
- Related to #596996
- Parent issue: #571422
- Previous backfill: !231589 (merged)
- Source of truth migration: !230811 (merged)
Screenshots or screen recordings
N/A — background migration with no UI changes.
| Before | After |
|---|---|
How to set up and validate locally
- Create
gitlab_subscriptionsrows with mismatched or NULLhosted_plan_name_uidvalues. - Run the migration:
bundle exec rails db:migrate:post_migrate. - Verify that
hosted_plan_name_uidnow matchesplans.plan_name_uidfor all affected rows.
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.``