From 0d51a47589bb8b647209fa29320c8b837288cccb Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Mon, 19 Apr 2021 12:30:45 +0200 Subject: [PATCH 1/2] Fix migration to DB version 242 from gvmd 20.08 When running the migration to DB version 242, the vt_severities table only exists when migrating from a 21.04 development version, so the migration for that table must be skipped if it does not exist. --- src/manage_migrators.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/manage_migrators.c b/src/manage_migrators.c index be1a0a67d..5ddf4a419 100644 --- a/src/manage_migrators.c +++ b/src/manage_migrators.c @@ -2627,10 +2627,20 @@ migrate_241_to_242 () sql ("ALTER TABLE results_trash DROP COLUMN IF EXISTS score;"); - /* Change the vt_severities table to a CVSS score */ - sql ("ALTER TABLE vt_severities ALTER COLUMN score" - " SET DATA TYPE double precision;"); - sql ("UPDATE vt_severities SET score = round((score / 10.0)::numeric, 1);"); + /* Change the vt_severities table to use a CVSS score + * if it already exists (migrating from a 21.04 development version) */ + if (sql_int ("SELECT EXISTS (SELECT * FROM information_schema.tables" + " WHERE table_catalog = '%s'" + " AND table_schema = 'public'" + " AND table_name = 'vt_severities')" + " ::integer;", + sql_database ())) + { + sql ("ALTER TABLE vt_severities ALTER COLUMN score" + " SET DATA TYPE double precision;"); + sql ("UPDATE vt_severities" + " SET score = round((score / 10.0)::numeric, 1);"); + } /* Set the database version to 242. */ From 1cd170fb15bac1972360f2fb1b763377ccbb012e Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Mon, 19 Apr 2021 14:06:29 +0200 Subject: [PATCH 2/2] Add CHANGELOG entry for migration fix --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb9cd5f97..7f378c1ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed - Improve VT version handling for CVE & OVAL results [#1496](https://github.com/greenbone/gvmd/pull/1496) +- Fix migration to DB version 242 from gvmd 20.08 [#1498](https://github.com/greenbone/gvmd/pull/1498) [21.4.0]: https://github.com/greenbone/gvmd/compare/v21.4.0...gvmd-21.04