Skip to content

Update the `namespace_id` of `vulnerability_reads` when project moves

What does this MR do and why?

With this change, we update the namespace_id of the vulnerability_reads records when the project is moved from one namespace to another. This will fix the discrepancies on the group-level vulnerability report page when one of the projects moves to another group.

Database review

Batch iteration queries
Finding the lower bound of the batch
SELECT
    "vulnerability_reads"."vulnerability_id"
FROM
    "vulnerability_reads"
WHERE
    "vulnerability_reads"."project_id" = 278964
ORDER BY
    "vulnerability_reads"."vulnerability_id" ASC
LIMIT 1

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/20981/commands/68666

Finding the upper bound of the batch
SELECT
    "vulnerability_reads"."vulnerability_id"
FROM
    "vulnerability_reads"
WHERE
    "vulnerability_reads"."project_id" = 278964
    AND "vulnerability_reads"."vulnerability_id" >= 1
ORDER BY
    "vulnerability_reads"."vulnerability_id" ASC
LIMIT 1 OFFSET 100

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/20981/commands/68667

An example update query for the batch
UPDATE
    "vulnerability_reads"
SET
    "namespace_id" = 83
WHERE
    "vulnerability_reads"."project_id" = 278964
    AND "vulnerability_reads"."vulnerability_id" >= 1
    AND "vulnerability_reads"."vulnerability_id" < 220

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/20981/commands/68669

Related to Group-level vulnerability reports do not show a... (#408764 - closed).

MR acceptance checklist

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

Edited by Mehmet Emin INAC

Merge request reports