|
| 1 | +-- Copyright (C) 2026 l3montree GmbH |
| 2 | +-- |
| 3 | +-- This program is free software: you can redistribute it and/or modify |
| 4 | +-- it under the terms of the GNU Affero General Public License as |
| 5 | +-- published by the Free Software Foundation, either version 3 of the |
| 6 | +-- License, or (at your option) any later version. |
| 7 | +-- |
| 8 | +-- This program is distributed in the hope that it will be useful, |
| 9 | +-- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | +-- GNU Affero General Public License for more details. |
| 12 | +-- |
| 13 | +-- You should have received a copy of the GNU Affero General Public License |
| 14 | +-- along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 15 | + |
| 16 | + |
| 17 | +DELETE FROM public.vuln_events |
| 18 | +WHERE user_id = 'system' |
| 19 | + AND dependency_vuln_id IS NOT NULL |
| 20 | + AND type IN ('fixed', 'reopened'); |
| 21 | + |
| 22 | +UPDATE public.dependency_vulns dv |
| 23 | +SET state = CASE last_event.type WHEN 'reopened' THEN 'open' WHEN 'detected' THEN 'open' ELSE last_event.type END |
| 24 | +FROM ( |
| 25 | + SELECT DISTINCT ON (dependency_vuln_id) dependency_vuln_id, type |
| 26 | + FROM public.vuln_events |
| 27 | + WHERE dependency_vuln_id IS NOT NULL |
| 28 | + AND type IN ('falsePositive', 'accepted', 'reopened', 'fixed', 'detected') |
| 29 | + ORDER BY dependency_vuln_id, created_at DESC |
| 30 | +) AS last_event |
| 31 | +WHERE dv.id = last_event.dependency_vuln_id |
| 32 | + AND dv.state != last_event.type; |
0 commit comments