From 0d51a47589bb8b647209fa29320c8b837288cccb Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Mon, 19 Apr 2021 12:30:45 +0200 Subject: [PATCH] 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. */