Skip to content

Add loose foreign key ci_pipeline_schedules.owner_id

What does this MR do and why?

Per #348268 (closed) we need to remove this foreign key and replace it with a "loose foreign key" https://docs.gitlab.com/ee/development/database/loose_foreign_keys.html .

It is safest to first add the LFK (as in this MR) and then remove the foreign key in a later MR. In the meantime the LFK will have nothing to cleanup as the foreign key is still cleaning up everything on delete.

Loose foreign keys are cleaned up async so we need to be sure it is safe to remove the foreign key first.

This seems like it should be safe based on:

$ git grep 'schedule.owner_id'

yielding no results.

Instead it seems to always be accessed as owner which already needs to handle nil as this column is allowed to be null.

$ git grep 'schedule.owner'
app/services/ci/pipeline_schedule_service.rb:      RunPipelineScheduleWorker.perform_async(schedule.id, schedule.owner&.id)
app/views/projects/pipeline_schedules/_pipeline_schedule.html.haml:      - if pipeline_schedule.owner
app/views/projects/pipeline_schedules/_pipeline_schedule.html.haml:        = image_tag avatar_icon_for_user(pipeline_schedule.owner, 20), class: "avatar s20"
app/views/projects/pipeline_schedules/_pipeline_schedule.html.haml:        = link_to user_path(pipeline_schedule.owner) do
app/views/projects/pipeline_schedules/_pipeline_schedule.html.haml:          = pipeline_schedule.owner&.name
app/workers/pipeline_schedule_worker.rb:        with_context(project: schedule.project, user: schedule.owner) do
app/workers/pipeline_schedule_worker.rb:          Ci::PipelineScheduleService.new(schedule.project, schedule.owner).execute(schedule)

... some other false positives/specs

... specs

Screenshots or screen recordings

These are strongly recommended to assist reviewers and reduce the time to merge your change.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #348268 (closed)

Edited by Fabio Pitino

Merge request reports