Skip to content

Add loose FK + model associations to vulnerability_occurrences cols

What does this MR do and why?

We want to drop the vulnerability_occurrence_pipelines table. In order to do this, we still need the first and latest pipeline ID stored somewhere to support the existing feature-set

We decided to store these values in vulnerability_occurrences, and added columns, along with indexes, in previous commits.

With that work done, we are now unblocked to add foreign keys and model associations, to prepare to actually backfill and use these columns

Loose Foreign Keys

As the pipelines table and the vulnerabilities table are in separate databases, we need to use loose foreign keys. As part of that process, I ran the script:

scripts/decomposition/generate-loose-foreign-key -c vulnerability_occurrences

This generated specs that were not passing. To make these specs pass I needed to modify the factories from:

let_it_be(:model) { create(:vulnerability_occurrences, initial_pipeline: parent) }
let_it_be(:model) { create(:vulnerability_occurrences, latest_pipeline: parent) }

to:

let_it_be(:model) { create(:vulnerabilities_finding, initial_pipeline_id: parent.id) }
let_it_be(:model) { create(:vulnerabilities_finding, latest_pipeline_id: parent.id) }

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.


related to: #422382 (closed)
resolves: #443284 (closed)
resolves: #443283 (closed)

Changelog: changed

Edited by Michael Becker

Merge request reports