Skip to content

Commit

Permalink
Merge pull request #2036 from greenbone/stricter-pref-migration-checks
Browse files Browse the repository at this point in the history
Fix: Make matching for prefs migration stricter
  • Loading branch information
timopollmeier authored Jul 6, 2023
2 parents 8419e4c + 976049d commit 6791ad3
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/manage_migrators.c
Original file line number Diff line number Diff line change
Expand Up @@ -3070,28 +3070,28 @@ migrate_253_to_254_alter (int trash)
trash ? "_trash" : "");
sql ("UPDATE config_preferences%s"
" SET pref_nvt = substring (name, '^([^:]*)')"
" WHERE name LIKE '%%:%%';",
" WHERE name ~ '^[^:]*:[0-9]+:[^:]*:.*';",
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)"
" WHERE name LIKE '%%:%%';",
" SET pref_id = CAST (substring (name, '^[^:]*:([0-9]+)') AS integer)"
" WHERE name ~ '^[^:]*:[0-9]+:[^:]*:.*';",
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, '^[^:]*:[^:]*:([^:]*):')"
" WHERE name LIKE '%%:%%';",
" SET pref_type = substring (name, '^[^:]*:[0-9]+:([^:]*):')"
" WHERE name ~ '^[^:]*:[0-9]+:[^:]*:.*';",
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, '^[^:]*:[^:]*:[^:]*:(.*)')"
" WHERE name LIKE '%%:%%';",
" SET pref_name = substring (name, '^[^:]*:[0-9]+:[^:]*:(.*)')"
" WHERE name ~ '^[^:]*:[0-9]+:[^:]*:.*';",
trash ? "_trash" : "");
}

Expand Down Expand Up @@ -3150,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 ~ '^[^:]*:[0-9]+:[^:]*:.*';");

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 '%%:%%';");
" SET pref_id = CAST (substring (name, '^[^:]*:([0-9]+)') AS integer)"
" WHERE name ~ '^[^:]*:[0-9]+:[^:]*:.*';");

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

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

/* Set the database version to 255. */

Expand Down

0 comments on commit 6791ad3

Please sign in to comment.