[open-ils-commits] r14791 - in trunk/Open-ILS/src/sql/Pg: . upgrade (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu Nov 5 14:27:42 EST 2009
Author: miker
Date: 2009-11-05 14:27:38 -0500 (Thu, 05 Nov 2009)
New Revision: 14791
Added:
trunk/Open-ILS/src/sql/Pg/upgrade/0073.schema.day-granular-circ-due-time.sql
Modified:
trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
trunk/Open-ILS/src/sql/Pg/090.schema.action.sql
Log:
forward-porting r14786 and r14787: use a trigger to push day-granular circ due_date to the end of the calendar day
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2009-11-05 19:27:04 UTC (rev 14790)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2009-11-05 19:27:38 UTC (rev 14791)
@@ -51,7 +51,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0071'); -- miker
+INSERT INTO config.upgrade_log (version) VALUES ('0073'); -- miker
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
Modified: trunk/Open-ILS/src/sql/Pg/090.schema.action.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/090.schema.action.sql 2009-11-05 19:27:04 UTC (rev 14790)
+++ trunk/Open-ILS/src/sql/Pg/090.schema.action.sql 2009-11-05 19:27:38 UTC (rev 14791)
@@ -153,7 +153,18 @@
CREATE TRIGGER mat_summary_change_tgr AFTER UPDATE ON action.circulation FOR EACH ROW EXECUTE PROCEDURE money.mat_summary_update ();
CREATE TRIGGER mat_summary_remove_tgr AFTER DELETE ON action.circulation FOR EACH ROW EXECUTE PROCEDURE money.mat_summary_delete ();
+CREATE OR REPLACE FUNCTION action.push_circ_due_time () RETURNS TRIGGER AS $$
+BEGIN
+ IF (EXTRACT(EPOCH FROM NEW.circ_duration)::INT % EXTRACT(EPOCH FROM '1 day'::INTERVAL)::INT) = 0 THEN
+ NEW.due_date = (NEW.due_date::DATE + '1 day'::INTERVAL - '1 second'::INTERVAL)::TIMESTAMPTZ;
+ END IF;
+ RETURN NEW;
+END;
+$$ LANGUAGE PLPGSQL;
+
+CREATE TRIGGER push_due_date_tgr BEFORE INSERT ON action.circulation FOR EACH ROW EXECUTE PROCEDURE action.push_circ_due_time();
+
CREATE TABLE action.aged_circulation (
usr_post_code TEXT,
usr_home_ou INT NOT NULL,
Added: trunk/Open-ILS/src/sql/Pg/upgrade/0073.schema.day-granular-circ-due-time.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0073.schema.day-granular-circ-due-time.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0073.schema.day-granular-circ-due-time.sql 2009-11-05 19:27:38 UTC (rev 14791)
@@ -0,0 +1,20 @@
+-- Already exists as far back as 1.6.0.0, so don't use this in version upgrades
+
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0073');
+
+CREATE OR REPLACE FUNCTION action.push_circ_due_time () RETURNS TRIGGER AS $$
+BEGIN
+ IF (EXTRACT(EPOCH FROM NEW.circ_duration)::INT % EXTRACT(EPOCH FROM '1 day'::INTERVAL)::INT) = 0 THEN
+ NEW.due_date = (NEW.due_date::DATE + '1 day'::INTERVAL - '1 second'::INTERVAL)::TIMESTAMPTZ;
+ END IF;
+
+ RETURN NEW;
+END;
+$$ LANGUAGE PLPGSQL;
+
+CREATE TRIGGER push_due_date_tgr BEFORE INSERT ON action.circulation FOR EACH ROW EXECUTE PROCEDURE action.push_circ_due_time();
+
+COMMIT;
+
More information about the open-ils-commits
mailing list