Add new column status_changed_time to asset.copy,
authorscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 20 Oct 2009 02:36:11 +0000 (02:36 +0000)
committerscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 20 Oct 2009 02:36:11 +0000 (02:36 +0000)
with a trigger to maintain it.

Add corresponding new column to auditor.asset_copy_history.

M    Open-ILS/src/sql/Pg/002.schema.config.sql
A    Open-ILS/src/sql/Pg/upgrade/0039.schema.acp_status_date_changed.sql
M    Open-ILS/examples/fm_IDL.xml

git-svn-id: svn://svn.open-ils.org/ILS/trunk@14502 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/examples/fm_IDL.xml
Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/upgrade/0039.schema.acp_status_date_changed.sql [new file with mode: 0644]

index dfc508d..fe7f6cc 100644 (file)
@@ -3290,6 +3290,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="Price" name="price" reporter:datatype="money" />
                        <field reporter:label="Is Reference" name="ref" reporter:datatype="bool"/>
                        <field reporter:label="Copy Status" name="status" reporter:datatype="link"/>
+                       <field reporter:label="Copy Status Changed Time" name="status_changed_time" reporter:datatype="timestamp"/>
                        <field reporter:label="Copy Notes" name="notes" oils_persist:virtual="true" reporter:datatype="link"/>
                        <field reporter:label="Stat-Cat entry maps" name="stat_cat_entry_copy_maps" oils_persist:virtual="true" reporter:datatype="link"/>
                        <field reporter:label="Circulations" name="circulations" oils_persist:virtual="true" reporter:datatype="link"/>
index b686236..fa183ad 100644 (file)
@@ -51,7 +51,7 @@ CREATE TABLE config.upgrade_log (
     install_date    TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
 );
 
-INSERT INTO config.upgrade_log (version) VALUES ('0038'); -- senator
+INSERT INTO config.upgrade_log (version) VALUES ('0039'); -- mck9
 
 
 CREATE TABLE config.bib_source (
diff --git a/Open-ILS/src/sql/Pg/upgrade/0039.schema.acp_status_date_changed.sql b/Open-ILS/src/sql/Pg/upgrade/0039.schema.acp_status_date_changed.sql
new file mode 100644 (file)
index 0000000..54b5d06
--- /dev/null
@@ -0,0 +1,28 @@
+BEGIN;
+
+-- Add new column status_changed_date to asset.copy, with trigger to maintain it
+-- Add corresponding new column to auditor.asset_copy_history
+
+INSERT INTO config.upgrade_log (version) VALUES ('0039'); -- mck9
+
+ALTER TABLE asset.copy
+       ADD COLUMN status_changed_time TIMESTAMPTZ;
+
+ALTER TABLE auditor.asset_copy_history
+       ADD COLUMN status_changed_time TIMESTAMPTZ;
+
+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();
+
+COMMIT;