Add backfill migrations for builds partition tracking

What does this MR do and why?

This MR adds the backfill migrations needed to populate the partition tracking data structures introduced in !228838 (merged). It is part of the corrective action for INC-8367.

This MR has been split out from !228838 (merged). The full work is tracked across the following MRs:

MR Description
!228838 (merged) Add ci_builds_partition_overrides table and builds_id_range column on ci_partitions
!229866 (closed) Add switching logic to capture partition range intervals
!231138 (closed) (this MR) Add backfill migrations for builds partition tracking
!231142 (closed) Add trigger to create overflow records

What is added

BackfillBuildsIdRangeOnCiPartitions (post-migrate) — backfills the builds_id_range column on existing ci_partitions rows by computing the min build ID per partition. For each partition, it sets the range as [min_id_in_partition, min_id_in_next_partition), leaving the last (active) partition with an open-ended range.

QueueBackfillCiBuildsPartitionOverrides (post-migrate) — enqueues a batched background migration (BackfillCiBuildsPartitionOverrides) to populate the override table for all existing spillover records. It processes each non-empty, non-current partition independently, using the builds_id_range boundaries to scope the batch correctly.

BackfillCiBuildsPartitionOverrides (background migration) — the actual BBM worker that inserts (build_id, partition_id, project_id) rows into ci_builds_partition_overrides for all builds in a given partition batch, using ON CONFLICT DO NOTHING for idempotency.

Why this approach

The backfill is necessary to ensure that existing spillover builds (those inserted into a non-active partition before the override table existed) are captured retroactively. Without this, the two-layer lookup introduced in !228838 (merged) and !229866 (closed) would only work for builds created after the trigger is installed.

Changelog: other

References

Screenshots or screen recordings

N/A — database migrations only

Before After

How to set up and validate locally

  1. Ensure !228838 (merged) is merged first (provides the ci_builds_partition_overrides table and builds_id_range column).
  2. Run db:migrate:post_deploy — verifies builds_id_range is backfilled on ci_partitions and the BBM is queued.
  3. Inspect ci_partitions rows to confirm builds_id_range is populated for all non-empty partitions.
  4. Run the spec suite for the background migration and migration specs.

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 #593701 (closed)

Edited by Marius Bobin

Merge request reports

Loading
Loading