Remove reverse-sync trigger and FKs from merge_request_diff_files_archived

Summary

Removes the reverse-sync trigger and both foreign keys from merge_request_diff_files_archived, the archived copy of merge_request_diff_files left behind by the 19.4 partitioning swap (!241924 (merged)). The table is no longer accessed by application code (classes: []) and the swap has been stable.

This is the first MR of a split (FK removal now, table drop later), per the dropping a database table guidance. The table itself is dropped in a follow-up MR.

Milestone: 19.4

Work item: #627149

Migrations

Three post-deployment migrations in execution order:

  1. 20260902162109 — Drop reverse-sync trigger table_sync_trigger_cd362c20e2_reverse + function table_sync_function_3f39f64fc3_reverse() on merge_request_diff_files
  2. 20260902162110 — Remove FK fk_rails_501aa0a391 (merge_request_diff_id → merge_request_diffs)
  3. 20260902162111 — Remove FK fk_0e3ba01603 (project_id → projects, was NOT VALID)

All down methods are faithful inverses:

  • Trigger down recreates function + trigger verbatim from the swap migration
  • FK down methods restore original validation state (fk_rails_501aa0a391 VALID, fk_0e3ba01603 NOT VALID)

Schema spec allowlist

Removing the FKs while the table (and its merge_request_diff_id / project_id columns) still exists trips the Database schema spec, which asserts every _id column has a matching FK. Per the split pattern, merge_request_diff_files_archived is added to removed_fks_map in spec/db/schema_spec.rb. The follow-up table-drop MR removes this allowlist entry along with the table.

Data deletion

None in this MR. No rows are deleted and the table is not dropped here. This MR only removes the reverse-sync trigger and the two foreign keys.

Note: once the reverse-sync trigger is gone, merge_request_diff_files_archived stops being kept current with the live table. That is intended, the archived copy is redundant (every row is a copy of a row in the live partitioned merge_request_diff_files) and the table is slated for removal in the follow-up MR.

Revertibility

All three migrations are individually revertible (see down methods above).

⚠️ Note for the follow-up table-drop MR: dropping merge_request_diff_files_archived will make the 19.4 swap migration (20260821135518) non-revertible, because the swap's down renames the archived table back into place. That risk is accepted there, not here. This MR does not affect the swap's revertibility.

Testing

  • All 3 migrations applied cleanly on GDK (main/ci/sec DBs)
  • All 3 down methods verified as faithful inverses
  • spec/db/schema_spec.rb passes for merge_request_diff_files_archived (7 examples, 0 failures) with the removed_fks_map entry
  • rubocop clean on all migration files

Follow-up

A subsequent MR (work item #627149) will:

  • Drop the merge_request_diff_files_archived table (migration 20260902162112)
  • Move db/docs/merge_request_diff_files_archived.yml → db/docs/deleted_tables/ with removed_by_url + removed_in_milestone
  • Remove the removed_fks_map entry added here
Edited by Kerri Miller

Merge request reports

Loading
Loading