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 NULLconstraint onproject_id. During project import,MergeRequestDiffFileobjects are bulk inserted withoutproject_idbeing set, which causes import failures. !247724 (merged) fixed this by propagatingproject_idfrom the parentMergeRequestDiffbefore bulk insert.
Changes
-
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.
-
Swap migration - Uses
replace_with_partitioned_tablehelper 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)
- Rename
-
Model update - Adds
PartitionedTableconcern andpartitioned_bydeclaration -
Partition manager - Updates registration to use new table name
-
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.
Related issues
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:
- Drops sync trigger on original table
- Renames original → archived
- Renames partitioned → original name
- Creates new sync trigger pointing to archived table