Add foreign key between ci_runner_projects and ci_runners
What does this MR do and why?
This MR does two things, each its commit:
- adds a foreign key between
ci_runner_projectsandci_runners, in the same way as thefk_rails_8767676b7aFK constraint that exists inci_runner_namespaces:
- adds a batched background migration to remove orphaned
ci_runner_projectsrecords. The FK constraint from the previous point will be validated after the required stop in %17.9 (hoping we can merge this in %17.8), but will for now avoid new records being left behind.
Changelog: added
References
Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.
- Add foreign key between ci_runner_projects and ... (#369084 - closed)
- https://gitlab.com/gitlab-org/gitlab/-/issues/510990+
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
This MR will delete around 30% of the ci_runner_projects records:
gitlabhq_dblab> SELECT COUNT(*) FROM ci_runner_projects WHERE NOT EXISTS (SELECT 1 FROM ci_runners WHERE ci_runners.id = ci_runner_projects.runner_id)
+--------+
| count |
|--------|
| 546619 |
+--------+
SELECT 1
Time: 17.769s (17 seconds), executed in: 17.768s (17 seconds)
gitlabhq_dblab> SELECT COUNT(*) FROM ci_runner_projects
+---------+
| count |
|---------|
| 1790283 |
+---------+
SELECT 1
Time: 1.927s (1 second), executed in: 1.925s (1 second)
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
Edited by Pedro Pombeiro
