From: Bill Erickson Date: Tue, 3 May 2016 14:40:14 +0000 (-0400) Subject: JBAS-533 Org units get their own mailing addresses X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=62857b71231f1d946cf508695751cd06e1560803;p=working%2FEvergreen.git JBAS-533 Org units get their own mailing addresses Give each org unit currently using address ID 1 as its mailing address a copy of address ID 1 so that it can be edited w/o modifying the addresses of other org units. Signed-off-by: Bill Erickson --- diff --git a/KCLS/sql/schema/deploy/org-unit-addrs-copy.sql b/KCLS/sql/schema/deploy/org-unit-addrs-copy.sql new file mode 100644 index 0000000000..649ea83d9b --- /dev/null +++ b/KCLS/sql/schema/deploy/org-unit-addrs-copy.sql @@ -0,0 +1,30 @@ +-- Deploy kcls-evergreen:org-unit-addrs-copy to pg +-- requires: sip-activity-types +BEGIN; + +-- Create a copy of address id=1 for each org unit that +-- currently links to address id=1 + +INSERT INTO actor.org_address (org_unit, address_type, + street1, street2, city, county, state, country, post_code, san) + SELECT aou.id, aua.address_type, aua.street1, aua.street2, + aua.city, aua.county, aua.state, aua.country, aua.post_code, aua.san + FROM actor.org_unit aou + JOIN actor.org_address aua ON (aua.id = aou.mailing_address) + WHERE aou.id <> 1; + +-- Update each org unit to use the newly created address whose +-- owning org unit value matches. Ignore existing addresses. + +UPDATE actor.org_unit aou + SET mailing_address = ( + SELECT aua.id + FROM actor.org_address aua + WHERE aua.org_unit = aou.id + -- avoid using addresses that existed before this script ran + AND aua.id NOT IN (1, 5, 6) + ) + WHERE id <> 1 AND mailing_address = 1; + +COMMIT; + diff --git a/KCLS/sql/schema/revert/org-unit-addrs-copy.sql b/KCLS/sql/schema/revert/org-unit-addrs-copy.sql new file mode 100644 index 0000000000..4eec3f14d0 --- /dev/null +++ b/KCLS/sql/schema/revert/org-unit-addrs-copy.sql @@ -0,0 +1,12 @@ +-- Revert kcls-evergreen:org-unit-addrs-copy from pg + +BEGIN; + +UPDATE actor.org_unit + SET mailing_address = 1 + WHERE mailing_address IS NOT NULL + AND mailing_address NOT IN (5, 6); + +DELETE FROM actor.org_address WHERE id NOT IN (1, 5, 6); + +COMMIT; diff --git a/KCLS/sql/schema/sqitch.plan b/KCLS/sql/schema/sqitch.plan index bb735d5d13..765dcfe49c 100644 --- a/KCLS/sql/schema/sqitch.plan +++ b/KCLS/sql/schema/sqitch.plan @@ -22,3 +22,4 @@ subject-browse-entry-dashes [2.5-to-2.7-upgrade] 2016-02-11T20:12:05Z Bill Erick patron-self-reg-mods [blanket-po-print-template] 2016-01-13T20:14:00Z Bill Erickson # Patron self-reg customizations sip-activity-types [2.7-auth-reingest] 2016-03-15T21:30:39Z Bill Erickson # User activity types for hoopla/lynda SIP auth ingram-edi-mods [sip-activity-types] 2016-05-24T16:31:46Z Bill Erickson # Ingram EDI config updates +org-unit-addrs-copy [sip-activity-types] 2016-05-03T14:17:59Z Bill Erickson # Give each org unit its own mailing address diff --git a/KCLS/sql/schema/verify/org-unit-addrs-copy.sql b/KCLS/sql/schema/verify/org-unit-addrs-copy.sql new file mode 100644 index 0000000000..6c106b15f5 --- /dev/null +++ b/KCLS/sql/schema/verify/org-unit-addrs-copy.sql @@ -0,0 +1,7 @@ +-- Verify kcls-evergreen:org-unit-addrs-copy on pg + +BEGIN; + +-- XXX Add verifications here. + +ROLLBACK;