LP#1527342 SQL / IDL
authorBill Erickson <berickxx@gmail.com>
Tue, 22 Dec 2015 20:43:31 +0000 (15:43 -0500)
committerBill Erickson <berickxx@gmail.com>
Tue, 22 Dec 2015 20:43:31 +0000 (15:43 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.decouple_co_history.sql

index e363e9a..4689e1c 100644 (file)
@@ -194,8 +194,16 @@ DECLARE
     cur_usr   INTEGER;
     cur_circ  action.circulation%ROWTYPE;
     last_circ action.circulation%ROWTYPE;
+    counter   INTEGER DEFAULT 1;
 BEGIN
 
+    RAISE NOTICE 
+        'Migrating circ history for % users.  This might take a while...',
+        (SELECT COUNT(DISTINCT(au.id)) FROM actor.usr au
+            JOIN actor.usr_setting aus ON (aus.usr = au.id)
+            WHERE NOT au.deleted AND 
+                aus.name ~ '^history.circ.retention_');
+
     FOR cur_usr IN 
         SELECT DISTINCT(au.id)
             FROM actor.usr au 
@@ -224,6 +232,13 @@ BEGIN
                 cur_circ.id
             );
 
+            -- useful for alleviating administrator anxiety.
+            IF counter % 10000 = 0 THEN
+                RAISE NOTICE 'Migrated history for % total users', counter;
+            END IF;
+
+            counter := counter + 1;
+
         END LOOP;
     END LOOP;