LP 1075401 - Upgrade script to nullify existing bad data
authorMichele Morgan <mmorgan@noblenet.org>
Mon, 3 Jul 2017 18:49:42 +0000 (14:49 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Mon, 7 Aug 2017 20:42:04 +0000 (16:42 -0400)
Sets to NULL any entries in asset.copy_template.age_protect and
asset.copy_template.circ_as_type that are not valid values.

Signed-off-by: Michele Morgan <mmorgan@noblenet.org>
Signed-off-by: Josh Stompro <stomproj@larl.org>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>

Open-ILS/src/sql/Pg/upgrade/XXXX.data.nullify_invalid_act.age_protect_act.circ_as_type.sql [new file with mode: 0644]

diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.nullify_invalid_act.age_protect_act.circ_as_type.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.nullify_invalid_act.age_protect_act.circ_as_type.sql
new file mode 100644 (file)
index 0000000..7eafe11
--- /dev/null
@@ -0,0 +1,35 @@
+BEGIN;
+
+-- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+\echo -----------------------------------------------------------
+\echo Setting invalid age_protect and circ_as_type entries to NULL,
+\echo otherwise they will break the Serial Copy Templates editor.
+\echo Please review any Serial Copy Templates listed below.
+\echo
+UPDATE asset.copy_template act
+SET age_protect = NULL
+FROM actor.org_unit aou
+WHERE aou.id=act.owning_lib
+   AND act.age_protect NOT IN
+   (
+   SELECT id FROM config.rule_age_hold_protect
+   )
+RETURNING act.id "Template ID", act.name "Template Name",
+          aou.shortname "Owning Lib",
+          'Age Protection value reset to null.' "Description";
+
+UPDATE asset.copy_template act
+SET circ_as_type = NULL
+FROM actor.org_unit aou
+WHERE aou.id=act.owning_lib
+   AND act.circ_as_type NOT IN
+   (
+   SELECT code FROM config.item_type_map
+   )
+RETURNING act.id "Template ID", act.name "Template Name",
+          aou.shortname "Owning Lib",
+          'Circ as Type value reset to null.' as "Description";
+
+\echo -----------End Serial Template Fix----------------
+COMMIT;