Skip to content

Convert events.author_id to users foreign key to a LFK

What does this MR do and why?

Convert events author_id to users foreign key to a LFK

Addressing: #429803 (closed)

Context

As part of the Cells project, we are converting normal foreign keys from tables that belong to different GitLab database schemas into LooseForeignKeys

In this MR, I mostly used the output of the script here.

events and users will be eventually belongs to two different databases main_cell and main_clusterwide, that's why we have to convert this FK to a LFK.

How to set up and validate locally

  • Pull the branch
  • Run the Migration in this branch rails db:migrate.
  • Restart Sidekiq gdk restart rails-background-jobs
  • In Rails console, run the following:
user = FactoryBot.create(:user)
puts user.id
ev = FactoryBot.create(:event, author: user, target: Epic.first, group: Group.first)
  • In PostgreSQL Console gdk psql run:
  1. DELETE FROM users where id = {FILL USER ID HERE}
  2. SELECT count(*) FROM events WHERE author_id = {FILL USER ID HERE}
  3. The count will be > 0 for a while, until the LFK CleanupJob runs then the count shall be 0, which means that it's working as expected

One more thing

This MR also adds an exclude filter to the script scripts/decomposition/generate-loose-foreign-key that makes it easy to exclude a foreign key from the generated loose foreign keys.

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 #429803 (closed)

Edited by Omar Qunsul

Merge request reports

Loading