Skip to content

Commit

Permalink
Fix migration to DB version 242 from gvmd 20.08
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
timopollmeier committed Apr 19, 2021
1 parent ca203c4 commit 0d51a47
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/manage_migrators.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */

Expand Down

0 comments on commit 0d51a47

Please sign in to comment.