Skip to content

Commit

Permalink
Fix: Fix pattern match for migrating preferences
Browse files Browse the repository at this point in the history
Migrating the config preferences now only tries to process ones
containing a colon.
Also, the format string for the NVT preferences migration is adusted
to ensure percent signs are correct.
  • Loading branch information
timopollmeier committed Jul 5, 2023
1 parent dc55989 commit c7a0004
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/manage_migrators.c
Original file line number Diff line number Diff line change
Expand Up @@ -3069,25 +3069,29 @@ migrate_253_to_254_alter (int trash)
sql ("ALTER TABLE config_preferences%s ADD COLUMN pref_nvt text;",
trash ? "_trash" : "");
sql ("UPDATE config_preferences%s"
" SET pref_nvt = substring (name, '^([^:]*)');",
" SET pref_nvt = substring (name, '^([^:]*)')"
" WHERE name LIKE '%%:%%';",
trash ? "_trash" : "");

sql ("ALTER TABLE config_preferences%s ADD COLUMN pref_id integer;",
trash ? "_trash" : "");
sql ("UPDATE config_preferences%s"
" SET pref_id = CAST (substring (name, '^[^:]*:([^:]*)') AS integer);",
" SET pref_id = CAST (substring (name, '^[^:]*:([^:]*)') AS integer)"
" WHERE name LIKE '%%:%%';",
trash ? "_trash" : "");

sql ("ALTER table config_preferences%s ADD COLUMN pref_type text;",
trash ? "_trash" : "");
sql ("UPDATE config_preferences%s"
" SET pref_type = substring (name, '^[^:]*:[^:]*:([^:]*):');",
" SET pref_type = substring (name, '^[^:]*:[^:]*:([^:]*):')"
" WHERE name LIKE '%%:%%';",
trash ? "_trash" : "");

sql ("ALTER table config_preferences%s ADD COLUMN pref_name text;",
trash ? "_trash" : "");
sql ("UPDATE config_preferences%s"
" SET pref_name = substring (name, '^[^:]*:[^:]*:[^:]*:(.*)');",
" SET pref_name = substring (name, '^[^:]*:[^:]*:[^:]*:(.*)')"
" WHERE name LIKE '%%:%%';",
trash ? "_trash" : "");
}

Expand Down Expand Up @@ -3146,22 +3150,22 @@ migrate_254_to_255 ()
sql ("ALTER TABLE nvt_preferences ADD COLUMN pref_nvt text;");
sql ("UPDATE nvt_preferences"
" SET pref_nvt = substring (name, '^([^:]*)')"
" WHERE name LIKE '%:%';");
" WHERE name LIKE '%%:%%';");

sql ("ALTER TABLE nvt_preferences ADD COLUMN pref_id integer;");
sql ("UPDATE nvt_preferences"
" SET pref_id = CAST (substring (name, '^[^:]*:([^:]*)') AS integer)"
" WHERE name LIKE '%:%';");
" WHERE name LIKE '%%:%%';");

sql ("ALTER table nvt_preferences ADD COLUMN pref_type text;");
sql ("UPDATE nvt_preferences"
" SET pref_type = substring (name, '^[^:]*:[^:]*:([^:]*):')"
" WHERE name LIKE '%:%';");
" WHERE name LIKE '%%:%%';");

sql ("ALTER table nvt_preferences ADD COLUMN pref_name text;");
sql ("UPDATE nvt_preferences"
" SET pref_name = substring (name, '^[^:]*:[^:]*:[^:]*:(.*)')"
" WHERE name LIKE '%:%';");
" WHERE name LIKE '%%:%%';");

/* Set the database version to 255. */

Expand Down

0 comments on commit c7a0004

Please sign in to comment.