Loading
Add merge_request_diff_id to approval_policy_merge_request_bypass_events
What does this MR do and why?
Adds a nullable merge_request_diff_id column to approval_policy_merge_request_bypass_events, so a bypass event records which merge request diff it was made against.
- One migration adds the column, an index (
index_approval_policy_mr_bypass_events_on_mr_diff_id), and a foreign key tomerge_request_diffswithON DELETE SET NULL. When an MR diff is deleted, we want service logic to handle deleting the bypass events tied to it. Security::ApprovalPolicyMergeRequestBypassEventnow hasbelongs_to :merge_request_diff, optional: true, with a matching model spec.
Database notes:
- Both tables are in
gitlab_main_org, so a real foreign key is allowed. approval_policy_merge_request_bypass_eventsissmall. The new column is allNULL, so creating the index and validating the foreign key are cheap.merge_request_diffsis high-traffic.add_concurrent_foreign_keytakes a shortSHARE ROW EXCLUSIVElock on it, with lock retries.- The migration runs outside a transaction (
disable_ddl_transaction!).add_columnusesif_not_existsso a partial run can be retried.downremoves the column, which drops the index and foreign key with it.
References
- #579429
- Depends on !273576 (merged)
Screenshots or screen recordings
Not applicable. This MR has no UI changes.
How to set up and validate locally
This MR has no user-facing change. It only changes the schema and the model association.
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 Jans Rautenbach