From a4d2abbe480bb86495a52b382f1f587fcf64a060 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Wed, 10 May 2017 10:00:46 -0700 Subject: [PATCH] LP#1552861: add upgrade script Also, a test plan for the fix: [1] Set the vandelay.default_match_set setting for several org units. In at least one case, set it to the ID of a valid vandelay.match_set entry; in another case, set it to a numeric ID that doesn't match any existing vms rows; and finally, in another case set it to the name of a match set. [2] Apply the patch and run the database update. Verify that the update script will indicate that there are invalid settings, then delete. [3] Open the library settings editor and verify that in the case where a valid match set was used, the editor provides a drop-down with possible vms values with the correct one selected. Signed-off-by: Galen Charlton Signed-off-by: Jeff Davis Signed-off-by: Galen Charlton --- ...data.change_default_match_set_ous_type.sql | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.data.change_default_match_set_ous_type.sql diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.change_default_match_set_ous_type.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.change_default_match_set_ous_type.sql new file mode 100644 index 0000000000..67ac1165b4 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.change_default_match_set_ous_type.sql @@ -0,0 +1,38 @@ +BEGIN; + +-- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); + +UPDATE config.org_unit_setting_type +SET datatype = 'link', fm_class = 'vms' +WHERE name = 'vandelay.default_match_set' +AND datatype = 'string' +AND fm_class IS NULL; + +\echo Existing vandelay.default_match_set that do not +\echo correspond to match sets +SELECT aou.shortname, aous.value +FROM actor.org_unit_setting aous +JOIN actor.org_unit aou ON (aou.id = aous.org_unit) +WHERE aous.name = 'vandelay.default_match_set' +AND ( + value !~ '^"[0-9]+"$' + OR + oils_json_to_text(aous.value)::INT NOT IN ( + SELECT id FROM vandelay.match_set + ) +); + +\echo And now deleting the bad values, as otherwise they +\echo will break the Library Settings Editor. +DELETE +FROM actor.org_unit_setting aous +WHERE aous.name = 'vandelay.default_match_set' +AND ( + value !~ '^"[0-9]+"$' + OR + oils_json_to_text(aous.value)::INT NOT IN ( + SELECT id FROM vandelay.match_set + ) +); + +COMMIT; -- 2.43.2