Swap merge_request_diff_files with partitioned table

What does this MR do and why?

Completes Step 4 of int-range partitioning for merge_request_diff_files by swapping the partitioned table into place as the primary table.

This is the final step in the partitioning migration:

  • Step 1 (18.3): Create partitioned copy with sync trigger
  • Step 2 (18.3): Enqueue backfill migration
  • Step 3 (18.10): Finalize backfill after required stop
  • Step 4 (19.2): Swap tables ← this MR

Dependencies

✅ Dependency merged: !247724 (merged) has been merged.

The partitioned table has a NOT NULL constraint on project_id. During project import, MergeRequestDiffFile objects are bulk inserted without project_id being set, which causes import failures. !247724 (merged) fixed this by propagating project_id from the parent MergeRequestDiff before bulk insert.

Changes

  1. FK validation migration - Validates foreign keys on the partitioned table. No-op on GitLab.com (already validated), ensures self-managed instances have validated FKs before swap.

  2. Swap migration - Uses replace_with_partitioned_table helper to:

    • Rename merge_request_diff_files → merge_request_diff_files_archived
    • Rename merge_request_diff_files_99208b8fac → merge_request_diff_files
    • Create sync trigger pointing to archived table (for rollback support)
  3. Model update - Adds PartitionedTable concern and partitioned_by declaration

  4. Partition manager - Updates registration to use new table name

  5. Spec cleanup - Removes obsolete sync trigger specs that tested the intermediate state

Partitioning details

  • Strategy: int_range by merge_request_diff_id
  • Partition size: 200M rows per partition
  • Sharding key: project_id

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Closes #422771 (closed)

Database

Migration: ValidateFksOnMergeRequestDiffFiles99208b8fac

No-op on GitLab.com (FKs already validated). For self-managed, validates:

  • fk_rails_ebcce501f5 (project_id → projects)
  • fk_rails_6fff895059 (merge_request_diff_id → merge_request_diffs)

Migration: SwapMergeRequestDiffFilesWithPartitionedTable

Uses replace_with_partitioned_table helper which:

  1. Drops sync trigger on original table
  2. Renames original → archived
  3. Renames partitioned → original name
  4. Creates new sync trigger pointing to archived table
Edited by Kerri Miller

Merge request reports

Loading
Loading