[open-ils-commits] r14504 - trunk/Open-ILS/src/sql/Pg (scottmk)
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Oct 20 11:03:35 EDT 2009
Author: scottmk
Date: 2009-10-20 11:03:33 -0400 (Tue, 20 Oct 2009)
New Revision: 14504
Modified:
trunk/Open-ILS/src/sql/Pg/040.schema.asset.sql
Log:
Add new status_changed_time to CREATE statement for asset.copy,
plus a trigger to maintain it.
Corresponding ALTER already committed in an upgrade script.
Modified: trunk/Open-ILS/src/sql/Pg/040.schema.asset.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/040.schema.asset.sql 2009-10-20 04:10:58 UTC (rev 14503)
+++ trunk/Open-ILS/src/sql/Pg/040.schema.asset.sql 2009-10-20 15:03:33 UTC (rev 14504)
@@ -60,7 +60,8 @@
alert_message TEXT,
opac_visible BOOL NOT NULL DEFAULT TRUE,
deleted BOOL NOT NULL DEFAULT FALSE,
- dummy_isbn TEXT
+ dummy_isbn TEXT,
+ status_changed_time TIMESTAMP WITH TIME ZONE
);
CREATE UNIQUE INDEX copy_barcode_key ON asset.copy (barcode) WHERE deleted IS FALSE;
CREATE INDEX cp_cn_idx ON asset.copy (call_number);
@@ -69,6 +70,20 @@
CREATE INDEX cp_editor_idx ON asset.copy ( editor );
CREATE RULE protect_copy_delete AS ON DELETE TO asset.copy DO INSTEAD UPDATE asset.copy SET deleted = TRUE WHERE OLD.id = asset.copy.id;
+CREATE OR REPLACE FUNCTION asset.acp_status_changed()
+RETURNS TRIGGER AS $$
+BEGIN
+ IF NEW.status <> OLD.status THEN
+ NEW.status_changed_time := now();
+ END IF;
+ RETURN NEW;
+END;
+$$ LANGUAGE plpgsql;
+
+CREATE TRIGGER acp_status_changed_trig
+ BEFORE UPDATE ON asset.copy
+ FOR EACH ROW EXECUTE PROCEDURE asset.acp_status_changed();
+
CREATE TABLE asset.copy_transparency (
id SERIAL PRIMARY KEY,
deposit_amount NUMERIC(6,2),
More information about the open-ils-commits
mailing list