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

Screenshots or screen recordings

N/A — background migration with no UI changes.

Before After

How to set up and validate locally

  1. Create gitlab_subscriptions rows with mismatched or NULL hosted_plan_name_uid values.
  2. Run the migration: bundle exec rails db:migrate:post_migrate.
  3. Verify that hosted_plan_name_uid now matches plans.plan_name_uid for 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.``

Edited by Florian Jedelhauser

Merge request reports

Loading
Loading