[open-ils-commits] r383 - conifer/trunk/tools/migration-scripts (dbs)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Apr 23 23:07:47 EDT 2009


Author: dbs
Date: 2009-04-23 23:07:45 -0400 (Thu, 23 Apr 2009)
New Revision: 383

Modified:
   conifer/trunk/tools/migration-scripts/windsor_patrons.sql
Log:
Add mobile and other phones to patron records
Use a less dumb UPDATE syntax


Modified: conifer/trunk/tools/migration-scripts/windsor_patrons.sql
===================================================================
--- conifer/trunk/tools/migration-scripts/windsor_patrons.sql	2009-04-24 02:24:13 UTC (rev 382)
+++ conifer/trunk/tools/migration-scripts/windsor_patrons.sql	2009-04-24 03:07:45 UTC (rev 383)
@@ -2,6 +2,8 @@
 DROP TABLE staging_patron_address;
 DROP TABLE staging_barcode;
 DROP TABLE staging_note;
+DROP TABLE staging_mobile_phone;
+DROP TABLE staging_other_phone;
 
 BEGIN;
 
@@ -9,11 +11,16 @@
 CREATE TABLE staging_patron_address (idfield SERIAL NOT NULL, barcode TEXT, address_type TEXT, street_1 TEXT, street_2 TEXT, city TEXT, county TEXT, province TEXT, country TEXT, postal_code TEXT);
 CREATE TABLE staging_barcode (idfield SERIAL NOT NULL, barcode TEXT, old_barcode TEXT, active BOOLEAN);
 CREATE TABLE staging_note (idfield SERIAL NOT NULL, barcode TEXT, create_date TEXT, publicly_visible BOOLEAN, title TEXT, note TEXT, create_date2 TEXT);
+CREATE TABLE staging_mobile_phone (idfield SERIAL NOT NULL, barcode TEXT, phone TEXT);
+CREATE TABLE staging_other_phone (idfield SERIAL NOT NULL, barcode TEXT, phone TEXT);
 
 COPY staging_patron (username, profile, identity_type, password, standing, identity_type2, identity_value, name_prefix, first_given_name, second_given_name, family_name, name_suffix, day_phone, evening_phone, other_phone, alert_message, home_library, active, barred, deleted, create_date, expire_date) FROM '/home/dbs/conifer/windsor_patron_load_base.csv';
 COPY staging_patron_address (barcode, address_type, street_1, street_2, city, county, province, country, postal_code) FROM '/home/dbs/conifer/windsor_patron_load_addresses.csv';
 COPY staging_barcode (barcode, old_barcode, active) FROM '/home/dbs/conifer/windsor_patron_load_barcodes.csv';
 COPY staging_note (barcode, create_date, publicly_visible, title, note, create_date2) FROM '/home/dbs/conifer/windsor_patron_load_notes.csv';
+COPY staging_mobile_phone (barcode, phone) FROM '/home/dbs/conifer/windsor_patron_load_phones_mobile.csv';
+COPY staging_other_phone (barcode, phone) FROM '/home/dbs/conifer/windsor_patron_load_phones_other.csv';
+
 COMMIT;
 
 ---- Let's find our duplicate usernames
@@ -153,24 +160,41 @@
         END AS alert_message,
         patron.create_date::DATE as create_date,
         patron.expire_date::DATE as expire_date
-    FROM staging_patron patron;
+    FROM staging_patron patron
+;
 
+-- And add our mobile and other phones to the patron record
+-- Mapping Windsor's "other" to evening_phone in Evergreen
+UPDATE actor.usr au 
+    SET evening_phone = TRIM(sop.phone)
+    FROM staging_other_phone sop
+    WHERE sop.barcode = au.ident_value
+;
+
+-- Mapping Windsor's "mobile" to other_phone in Evergreen
+UPDATE actor.usr au 
+    SET day_phone = TRIM(smp.phone)
+    FROM staging_mobile_phone smp
+    WHERE smp.barcode = au.ident_value
+;
+
 -- Now we need to generate actor.card entries
+-- And be careful to distinguish Windsor vs. existing entries
 INSERT INTO actor.card (usr, barcode, active) 
     SELECT au.id, au.ident_value, 't'
     FROM actor.usr au
     WHERE au.ident_value IS NOT NULL
+    AND au.home_ou IN (109, 122)
     AND au.ident_value NOT IN (SELECT barcode FROM actor.card)
     AND au.id > 1
 ;
 
-UPDATE actor.usr au SET card = (
-    SELECT ac.id
+UPDATE actor.usr au SET card = ac.id
     FROM actor.card ac
     WHERE ac.barcode = au.ident_value
     AND au.card IS NULL
     AND au.id > 1
-);
+;
 
 -- Get rid of the "old" barcodes that we inserted into actor.usr
 DELETE FROM staging_barcode
@@ -191,7 +215,8 @@
 
 UPDATE staging_patron_address
     SET address_type = NULL
-    WHERE TRIM(address_type) = '';
+    WHERE TRIM(address_type) = ''
+;
 
 INSERT INTO actor.usr_address (usr, address_type, street1, street2, city, state, county, country, post_code) 
     SELECT DISTINCT



More information about the open-ils-commits mailing list