Commit 67cd3d9a authored by Victor Zagorodny's avatar Victor Zagorodny Committed by Andreas Brandl

Fix the flakiness of SetReportTypeForVulnerabilities migration

parent 4aa274aa
...@@ -4,12 +4,20 @@ class SetReportTypeForVulnerabilities < ActiveRecord::Migration[5.2] ...@@ -4,12 +4,20 @@ class SetReportTypeForVulnerabilities < ActiveRecord::Migration[5.2]
DOWNTIME = false DOWNTIME = false
def up def up
# set report_type based on associated vulnerability_occurrences # set report_type based on vulnerability_occurrences from which the vulnerabilities were promoted,
# that is, first vulnerability_occurrences among those having the same vulnerability_id
execute <<~SQL execute <<~SQL
WITH first_findings_for_vulnerabilities AS (
SELECT MIN(id) AS id, vulnerability_id
FROM vulnerability_occurrences
WHERE vulnerability_id IS NOT NULL
GROUP BY vulnerability_id
)
UPDATE vulnerabilities UPDATE vulnerabilities
SET report_type = vulnerability_occurrences.report_type SET report_type = vulnerability_occurrences.report_type
FROM vulnerability_occurrences FROM vulnerability_occurrences, first_findings_for_vulnerabilities
WHERE vulnerabilities.id = vulnerability_occurrences.vulnerability_id WHERE vulnerability_occurrences.id = first_findings_for_vulnerabilities.id
AND vulnerabilities.id = vulnerability_occurrences.vulnerability_id
SQL SQL
# set default report_type for orphan vulnerabilities (there should be none but...) # set default report_type for orphan vulnerabilities (there should be none but...)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment