[open-ils-commits] r20476 - in branches/rel_2_1/Open-ILS/src/sql/Pg: . upgrade (gmc)

svn at svn.open-ils.org svn at svn.open-ils.org
Fri May 13 17:00:36 EDT 2011


Author: gmc
Date: 2011-05-13 17:00:30 -0400 (Fri, 13 May 2011)
New Revision: 20476

Added:
   branches/rel_2_1/Open-ILS/src/sql/Pg/upgrade/0533.schema.fix_age_circ.sql
Modified:
   branches/rel_2_1/Open-ILS/src/sql/Pg/002.schema.config.sql
Log:
add missing update script for change to circ age stored procedure

Signed-off-by: Galen Charlton <gmc at esilibrary.com>

Modified: branches/rel_2_1/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- branches/rel_2_1/Open-ILS/src/sql/Pg/002.schema.config.sql	2011-05-13 20:57:59 UTC (rev 20475)
+++ branches/rel_2_1/Open-ILS/src/sql/Pg/002.schema.config.sql	2011-05-13 21:00:30 UTC (rev 20476)
@@ -57,7 +57,7 @@
     install_date    TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
 );
 
-INSERT INTO config.upgrade_log (version) VALUES ('0532'); -- gmc
+INSERT INTO config.upgrade_log (version) VALUES ('0533'); -- gmc
 
 CREATE TABLE config.bib_source (
 	id		SERIAL	PRIMARY KEY,

Added: branches/rel_2_1/Open-ILS/src/sql/Pg/upgrade/0533.schema.fix_age_circ.sql
===================================================================
--- branches/rel_2_1/Open-ILS/src/sql/Pg/upgrade/0533.schema.fix_age_circ.sql	                        (rev 0)
+++ branches/rel_2_1/Open-ILS/src/sql/Pg/upgrade/0533.schema.fix_age_circ.sql	2011-05-13 21:00:30 UTC (rev 20476)
@@ -0,0 +1,44 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0533'); -- gmc
+
+CREATE OR REPLACE FUNCTION action.age_circ_on_delete () RETURNS TRIGGER AS $$
+DECLARE
+found char := 'N';
+BEGIN
+
+    -- If there are any renewals for this circulation, don't archive or delete
+    -- it yet.   We'll do so later, when we archive and delete the renewals.
+
+    SELECT 'Y' INTO found
+    FROM action.circulation
+    WHERE parent_circ = OLD.id
+    LIMIT 1;
+
+    IF found = 'Y' THEN
+        RETURN NULL;  -- don't delete
+	END IF;
+
+    -- Archive a copy of the old row to action.aged_circulation
+
+    INSERT INTO action.aged_circulation
+        (id,usr_post_code, usr_home_ou, usr_profile, usr_birth_year, copy_call_number, copy_location,
+        copy_owning_lib, copy_circ_lib, copy_bib_record, xact_start, xact_finish, target_copy,
+        circ_lib, circ_staff, checkin_staff, checkin_lib, renewal_remaining, grace_period, due_date,
+        stop_fines_time, checkin_time, create_time, duration, fine_interval, recurring_fine,
+        max_fine, phone_renewal, desk_renewal, opac_renewal, duration_rule, recurring_fine_rule,
+        max_fine_rule, stop_fines, workstation, checkin_workstation, checkin_scan_time, parent_circ)
+      SELECT
+        id,usr_post_code, usr_home_ou, usr_profile, usr_birth_year, copy_call_number, copy_location,
+        copy_owning_lib, copy_circ_lib, copy_bib_record, xact_start, xact_finish, target_copy,
+        circ_lib, circ_staff, checkin_staff, checkin_lib, renewal_remaining, grace_period, due_date,
+        stop_fines_time, checkin_time, create_time, duration, fine_interval, recurring_fine,
+        max_fine, phone_renewal, desk_renewal, opac_renewal, duration_rule, recurring_fine_rule,
+        max_fine_rule, stop_fines, workstation, checkin_workstation, checkin_scan_time, parent_circ
+        FROM action.all_circulation WHERE id = OLD.id;
+
+    RETURN OLD;
+END;
+$$ LANGUAGE 'plpgsql';
+
+COMMIT;



More information about the open-ils-commits mailing list