JBAS-533 Org units get their own mailing addresses
authorBill Erickson <berickxx@gmail.com>
Tue, 3 May 2016 14:40:14 +0000 (10:40 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
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 <berickxx@gmail.com>
KCLS/sql/schema/deploy/org-unit-addrs-copy.sql [new file with mode: 0644]
KCLS/sql/schema/revert/org-unit-addrs-copy.sql [new file with mode: 0644]
KCLS/sql/schema/sqitch.plan
KCLS/sql/schema/verify/org-unit-addrs-copy.sql [new file with mode: 0644]

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 (file)
index 0000000..649ea83
--- /dev/null
@@ -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 (file)
index 0000000..4eec3f1
--- /dev/null
@@ -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;
index bb735d5..765dcfe 100644 (file)
@@ -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 <berickxx@gmail.com> # Patron self-reg customizations
 sip-activity-types [2.7-auth-reingest] 2016-03-15T21:30:39Z Bill Erickson <berickxx@gmail.com> # User activity types for hoopla/lynda SIP auth
 ingram-edi-mods [sip-activity-types] 2016-05-24T16:31:46Z Bill Erickson <berickxx@gmail.com> # Ingram EDI config updates
+org-unit-addrs-copy [sip-activity-types] 2016-05-03T14:17:59Z Bill Erickson <berickxx@gmail.com> # 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 (file)
index 0000000..6c106b1
--- /dev/null
@@ -0,0 +1,7 @@
+-- Verify kcls-evergreen:org-unit-addrs-copy on pg
+
+BEGIN;
+
+-- XXX Add verifications here.
+
+ROLLBACK;