From: scottmk Date: Tue, 20 Oct 2009 15:03:33 +0000 (+0000) Subject: Add new status_changed_time to CREATE statement for asset.copy, X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=24073c0df8fff9daed419ff8a0394c82f5b89fef;p=contrib%2FConifer.git 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. git-svn-id: svn://svn.open-ils.org/ILS/trunk@14504 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/sql/Pg/040.schema.asset.sql b/Open-ILS/src/sql/Pg/040.schema.asset.sql index 5baaa1d314..1f25cfe5e1 100644 --- a/Open-ILS/src/sql/Pg/040.schema.asset.sql +++ b/Open-ILS/src/sql/Pg/040.schema.asset.sql @@ -60,7 +60,8 @@ CREATE TABLE asset.copy ( 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_creator_idx ON asset.copy ( creator ); 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),