Skip to content

Add FK to resource link events asynchrously

euko requested to merge 424114-create-fk-resource-link-events-async into master

What does this MR do and why?

Related to #424114 (closed)

system_note_metadata table's primary key column id needs to be converted to use bigint type.

id_convert_to_bigint is the new column that's been backfilled and uses bigint.

  1. This MR adds a new FK that will be used to reference id_convert_to_bigint when it's converted to id later.

resource_link_events references system_note_metadata's id with the constraint:

"fk_2a039c40f4" FOREIGN KEY (system_note_metadata_id) REFERENCES system_note_metadata(id) ON DELETE CASCADE -- existing FK

The above constraint needs to be replaced with a new FK:

-- This will replace "fk_2a039c40f4" in a later MR.
"fk_system_note_metadata_id_convert_to_bigint" FOREIGN KEY (system_note_metadata_id) REFERENCES system_note_metadata(id_convert_to_bigint) ON DELETE CASCADE NOT VALID 

The new FK is added and validated asynchronously for the .com database in this MR. For self-hosted, the corresponding FK will be added at the time of the swap along with the updated structure.sql then in Swap system_note_metadata.id to bigint (!141220 - merged).

  1. The MR also no-ops a migration previously shipped. The explanation is in !141333 (comment 1730027749).

Validation steps

Execute the migrations and check resource_link_events's metadata:

gdk psql

gitlabhq_development=# \d resource_link_events
Foreign-key constraints:
    "fk_2a039c40f4" FOREIGN KEY (system_note_metadata_id) REFERENCES system_note_metadata(id) ON DELETE CASCADE
    "fk_bd4ae15ce4" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
    "fk_rails_0cea73eba5" FOREIGN KEY (child_work_item_id) REFERENCES issues(id) ON DELETE CASCADE
    "fk_rails_da5dd8a56f" FOREIGN KEY (issue_id) REFERENCES issues(id) ON DELETE CASCADE
+    "fk_system_note_metadata_id_convert_to_bigint" FOREIGN KEY (system_note_metadata_id) REFERENCES system_note_metadata(id_convert_to_bigint) ON DELETE CASCADE NOT VALID
Edited by euko

Merge request reports

Loading