Finalize DeduplicatePipelineIids batched migrations

What does this MR do and why?

Context

p_ci_pipelines has a unique index — (project_id, iid, partition_id) — which enforces iid uniqueness within a partition but not across them, so duplicate (project_id, iid) pairs accumulated until 18.10. We've since prevented duplicates with the new p_ci_pipeline_iids table and its triggers.

In !240748 (merged), we introduced DeduplicatePipelineIids (%19.2), which cleaned up existing duplicates by reassigning a fresh iid to every pipeline with a duplicate.

This MR

Finalizes the BBM. It completed on GitLab.com and was queued in 19.2 — a required stop — so finalizing in 19.4 satisfies the rule that a BBM be queued at or before the last required stop.

The queue migration created one BBM per physical partition, so we do the same when finalizing. It skips the BBMs that don't exist.

BBM completion confirmation

Ran the duplicate-count query below against a postgres.ai thin clone of the production CI database. No duplicates remain.

Duplicate-count query
SELECT
    COUNT(DISTINCT project_id) AS projects_count,
    COUNT(*) AS distinct_dup_count,
    SUM(dup_count) AS total_dup_count,
    MAX(dup_count) AS max_dup_count_per_distinct_dup
FROM (
    SELECT project_id, iid, COUNT(*) AS dup_count
    FROM p_ci_pipelines
    WHERE iid IS NOT NULL
    GROUP BY project_id, iid
    HAVING COUNT(*) > 1
) duplicates;
 projects_count | distinct_dup_count | total_dup_count | max_dup_count_per_distinct_dup 
----------------+--------------------+-----------------+--------------------------------
              0 |                  0 |                 |                               

Confirmed the BBMs are completed on GitLab.com:

/chatops gitlab run batched_background_migrations list --database ci --job-class-name DeduplicatePipelineIids
ChatOps results

Screenshot_2026-08-17_at_2.44.44_PM

Screenshot_2026-08-17_at_2.44.52_PM

Changelog: other

References

Closes Finalize `DeduplicatePipelineIids` BBMs (#603644 - closed)

How to set up and validate locally

  1. Run the migration on both the development and test databases:

    bundle exec rails db:migrate
    RAILS_ENV=test bundle exec rails db:migrate
  2. Run the new spec alongside the queueing migration's spec:

    bundle exec rspec spec/migrations/20260817143000_finalize_deduplicate_pipeline_iids_spec.rb \
      spec/migrations/20260611192449_queue_deduplicate_pipeline_iids_spec.rb

    3 examples, 0 failures.

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 Leaminn Ma

Merge request reports

Loading
Loading