Add history tables, in the acq schema, for acq.purchase_order
authorscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 26 Jan 2010 21:40:32 +0000 (21:40 +0000)
committerscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 26 Jan 2010 21:40:32 +0000 (21:40 +0000)
and acq.lineitem.

See KCLS tickets 4304 and 2172.

M    Open-ILS/src/sql/Pg/002.schema.config.sql
A    Open-ILS/src/sql/Pg/upgrade/0140.schema.acq-audit-funcs.sql
A    Open-ILS/src/sql/Pg/201.acq.audit-functions.sql
M    Open-ILS/examples/fm_IDL.xml

git-svn-id: svn://svn.open-ils.org/ILS/trunk@15390 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/201.acq.audit-functions.sql [new file with mode: 0644]
Open-ILS/src/sql/Pg/upgrade/0140.schema.acq-audit-funcs.sql [new file with mode: 0644]

index 222fbbb..0a2324f 100644 (file)
@@ -4844,6 +4844,35 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                </permacrud>
        </class>
 
+       <class id="acqpoh" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="acq::acq_purchase_order_history" oils_persist:tablename="acq.acq_purchase_order_history" reporter:label="Purchase Order History">
+               <fields oils_persist:primary="audit_id" oils_persist:sequence="acq.acq_purchase_order_pkey_seq">
+                       <field reporter:label="Audit ID" name="audit_id" reporter:datatype="id"/>
+                       <field reporter:label="Audit Time" name="audit_time" reporter:datatype="timestamp"/>
+                       <field reporter:label="Audit Action" name="audit_action" reporter:datatype="text"/>
+                       <field reporter:label="Purchase Order ID" name="id" reporter:datatype="link"/>
+                       <field reporter:label="Owner" name="owner" reporter:datatype="link"/>
+                       <field reporter:label="Creator" name="creator" reporter:datatype="link"/>
+                       <field reporter:label="Editor" name="editor" reporter:datatype="link"/>
+                       <field reporter:label="Ordering Agency" name="ordering_agency" reporter:datatype="link"/>
+                       <field reporter:label="Create Time" name="create_time" reporter:datatype="timestamp"/>
+                       <field reporter:label="Edit Time" name="edit_time" reporter:datatype="timestamp"/>
+                       <field reporter:label="Provider" name="provider" reporter:datatype="link"/>
+                       <field reporter:label="State" name="state" reporter:datatype="text"/>
+                       <field reporter:label="Order Date" name="order_date" reporter:datatype="timestamp"/>
+                       <field reporter:label="Name" name="name" reporter:datatype="text"/>
+               </fields>
+               <links>
+                       <link field="id" reltype="has_a" key="id" map="" class="acqpo"/>
+                       <link field="owner" reltype="has_a" key="id" map="" class="au"/>
+                       <link field="creator" reltype="has_a" key="id" map="" class="au"/>
+                       <link field="editor" reltype="has_a" key="id" map="" class="au"/>
+                       <link field="ordering_agency" reltype="has_a" key="id" map="" class="aou"/>
+                       <link field="provider" reltype="has_a" key="id" map="" class="acqpro"/>
+               </links>
+               <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+               </permacrud>
+       </class>
+
        <class id="acqpon" controller="open-ils.cstore open-ils.reporter-store" oils_obj:fieldmapper="acq::po_note" oils_persist:tablename="acq.po_note" reporter:label="PO Note">
                <fields oils_persist:primary="id" oils_persist:sequence="acq.po_note_id_seq">
                        <field reporter:label="PO Note ID" name="id" reporter:datatype="id" />
@@ -4896,6 +4925,41 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                </links>
        </class>
 
+       <class id="acqlih" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="acq::acq_lineitem_history" oils_persist:tablename="acq.acq_lineitem_history" reporter:label="Line Item History">
+               <fields oils_persist:primary="audit_id" oils_persist:sequence="acq.acq_lineitem_pkey_seq">
+                       <field reporter:label="Audit ID" name="audit_id" reporter:datatype="id"/>
+                       <field reporter:label="Audit Time" name="audit_time" reporter:datatype="timestamp"/>
+                       <field reporter:label="Audit Action" name="audit_action" reporter:datatype="text"/>
+                       <field reporter:label="Lineitem ID" name="id" reporter:datatype="link"/>
+                       <field reporter:label="Creator" name="creator" reporter:datatype="link"/>
+                       <field reporter:label="Editor" name="editor" reporter:datatype="link"/>
+                       <field reporter:label="Selector" name="selector" reporter:datatype="link"/>
+                       <field reporter:label="Provider" name="provider" reporter:datatype="link"/>
+                       <field reporter:label="Purchase Order" name="purchase_order" reporter:datatype="link"/>
+                       <field reporter:label="Picklist" name="picklist" reporter:datatype="link"/>
+                       <field reporter:label="Expected Receive Time" name="expected_recv_time" reporter:datatype="timestamp"/>
+                       <field reporter:label="Create Time" name="create_time" reporter:datatype="timestamp"/>
+                       <field reporter:label="Edit Time" name="edit_time" reporter:datatype="timestamp"/>
+                       <field reporter:label="MARC" name="marc" reporter:datatype="text"/>
+                       <field reporter:label="Evergreen Bib ID" name="eg_bib_id" reporter:datatype="link"/>
+                       <field reporter:label="Source Label" name="source_label" reporter:datatype="text"/>
+                       <field reporter:label="Item Count" name="item_count" reporter:datatype="int"/>
+                       <field reporter:label="State" name="state" reporter:datatype="text"/>
+               </fields>
+               <links>
+                       <link field="id" reltype="has_a" key="id" map="" class="jub"/>
+                       <link field="creator" reltype="has_a" key="id" map="" class="au"/>
+                       <link field="editor" reltype="has_a" key="id" map="" class="au"/>
+                       <link field="selector" reltype="has_a" key="id" map="" class="au"/>
+                       <link field="provider" reltype="has_a" key="id" map="" class="acqpro"/>
+                       <link field="purchase_order" reltype="has_a" key="id" map="" class="acqpo"/>
+                       <link field="picklist" reltype="has_a" key="id" map="" class="acqpl"/>
+                       <link field="eg_bib_id" reltype="has_a" key="id" map="" class="bre"/>
+               </links>
+               <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+               </permacrud>
+       </class>
+
        <class id="acqlin" controller="open-ils.cstore open-ils.reporter-store" oils_obj:fieldmapper="acq::lineitem_note" oils_persist:tablename="acq.lineitem_note" reporter:label="Line Item Note">
                <fields oils_persist:primary="id" oils_persist:sequence="acq.lineitem_note_id_seq">
                        <field reporter:label="PO Line Item Note ID" name="id" reporter:datatype="id" />
index 343cd9b..d88ab07 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 ('0139'); -- Dan Wells via miker
+INSERT INTO config.upgrade_log (version) VALUES ('0140'); -- Scott McKellar
 
 CREATE TABLE config.bib_source (
        id              SERIAL  PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/201.acq.audit-functions.sql b/Open-ILS/src/sql/Pg/201.acq.audit-functions.sql
new file mode 100644 (file)
index 0000000..51f3507
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2004-2008  Georgia Public Library Service
+ * Copyright (C) 2007-2008  Equinox Software, Inc.
+ * Scott McKellar <scott@esilibrary.com> 
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+BEGIN;
+
+CREATE OR REPLACE FUNCTION acq.create_acq_seq     ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
+BEGIN
+    EXECUTE $$
+        CREATE SEQUENCE acq.$$ || sch || $$_$$ || tbl || $$_pkey_seq;
+    $$;
+       RETURN TRUE;
+END;
+$creator$ LANGUAGE 'plpgsql';
+
+CREATE OR REPLACE FUNCTION acq.create_acq_history ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
+BEGIN
+    EXECUTE $$
+        CREATE TABLE acq.$$ || sch || $$_$$ || tbl || $$_history (
+            audit_id   BIGINT                          PRIMARY KEY,
+            audit_time TIMESTAMP WITH TIME ZONE        NOT NULL,
+            audit_action       TEXT                            NOT NULL,
+            LIKE $$ || sch || $$.$$ || tbl || $$
+        );
+    $$;
+       RETURN TRUE;
+END;
+$creator$ LANGUAGE 'plpgsql';
+
+CREATE OR REPLACE FUNCTION acq.create_acq_func    ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
+BEGIN
+    EXECUTE $$
+        CREATE OR REPLACE FUNCTION acq.audit_$$ || sch || $$_$$ || tbl || $$_func ()
+        RETURNS TRIGGER AS $func$
+        BEGIN
+            INSERT INTO acq.$$ || sch || $$_$$ || tbl || $$_history
+                SELECT nextval('acq.$$ || sch || $$_$$ || tbl || $$_pkey_seq'),
+                    now(),
+                    SUBSTR(TG_OP,1,1),
+                    OLD.*;
+            RETURN NULL;
+        END;
+        $func$ LANGUAGE 'plpgsql';
+    $$;
+       RETURN TRUE;
+END;
+$creator$ LANGUAGE 'plpgsql';
+
+CREATE OR REPLACE FUNCTION acq.create_acq_update_trigger ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
+BEGIN
+    EXECUTE $$
+        CREATE TRIGGER audit_$$ || sch || $$_$$ || tbl || $$_update_trigger
+            AFTER UPDATE OR DELETE ON $$ || sch || $$.$$ || tbl || $$ FOR EACH ROW
+            EXECUTE PROCEDURE acq.audit_$$ || sch || $$_$$ || tbl || $$_func ();
+    $$;
+       RETURN TRUE;
+END;
+$creator$ LANGUAGE 'plpgsql';
+
+CREATE OR REPLACE FUNCTION acq.create_acq_lifecycle     ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
+BEGIN
+    EXECUTE $$
+        CREATE OR REPLACE VIEW acq.$$ || sch || $$_$$ || tbl || $$_lifecycle AS
+            SELECT     -1, now() as audit_time, '-' as audit_action, *
+              FROM     $$ || sch || $$.$$ || tbl || $$
+                UNION ALL
+            SELECT     *
+              FROM     acq.$$ || sch || $$_$$ || tbl || $$_history;
+    $$;
+       RETURN TRUE;
+END;
+$creator$ LANGUAGE 'plpgsql';
+
+
+-- The main event
+
+CREATE OR REPLACE FUNCTION acq.create_acq_auditor ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
+BEGIN
+    PERFORM acq.create_acq_seq(sch, tbl);
+    PERFORM acq.create_acq_history(sch, tbl);
+    PERFORM acq.create_acq_func(sch, tbl);
+    PERFORM acq.create_acq_update_trigger(sch, tbl);
+    PERFORM acq.create_acq_lifecycle(sch, tbl);
+    RETURN TRUE;
+END;
+$creator$ LANGUAGE 'plpgsql';
+
+SELECT acq.create_acq_auditor ( 'acq', 'purchase_order' );
+CREATE INDEX acq_po_hist_id_idx            ON acq.acq_purchase_order_history( id );
+
+SELECT acq.create_acq_auditor ( 'acq', 'lineitem' );
+CREATE INDEX acq_lineitem_hist_id_idx            ON acq.acq_lineitem_history( id );
+
+COMMIT;
diff --git a/Open-ILS/src/sql/Pg/upgrade/0140.schema.acq-audit-funcs.sql b/Open-ILS/src/sql/Pg/upgrade/0140.schema.acq-audit-funcs.sql
new file mode 100644 (file)
index 0000000..4c4bfdc
--- /dev/null
@@ -0,0 +1,92 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0140'); -- Scott McKellar
+
+CREATE OR REPLACE FUNCTION acq.create_acq_seq     ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
+BEGIN
+    EXECUTE $$
+        CREATE SEQUENCE acq.$$ || sch || $$_$$ || tbl || $$_pkey_seq;
+    $$;
+       RETURN TRUE;
+END;
+$creator$ LANGUAGE 'plpgsql';
+
+CREATE OR REPLACE FUNCTION acq.create_acq_history ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
+BEGIN
+    EXECUTE $$
+        CREATE TABLE acq.$$ || sch || $$_$$ || tbl || $$_history (
+            audit_id   BIGINT                          PRIMARY KEY,
+            audit_time TIMESTAMP WITH TIME ZONE        NOT NULL,
+            audit_action       TEXT                            NOT NULL,
+            LIKE $$ || sch || $$.$$ || tbl || $$
+        );
+    $$;
+       RETURN TRUE;
+END;
+$creator$ LANGUAGE 'plpgsql';
+
+CREATE OR REPLACE FUNCTION acq.create_acq_func    ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
+BEGIN
+    EXECUTE $$
+        CREATE OR REPLACE FUNCTION acq.audit_$$ || sch || $$_$$ || tbl || $$_func ()
+        RETURNS TRIGGER AS $func$
+        BEGIN
+            INSERT INTO acq.$$ || sch || $$_$$ || tbl || $$_history
+                SELECT nextval('acq.$$ || sch || $$_$$ || tbl || $$_pkey_seq'),
+                    now(),
+                    SUBSTR(TG_OP,1,1),
+                    OLD.*;
+            RETURN NULL;
+        END;
+        $func$ LANGUAGE 'plpgsql';
+    $$;
+       RETURN TRUE;
+END;
+$creator$ LANGUAGE 'plpgsql';
+
+CREATE OR REPLACE FUNCTION acq.create_acq_update_trigger ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
+BEGIN
+    EXECUTE $$
+        CREATE TRIGGER audit_$$ || sch || $$_$$ || tbl || $$_update_trigger
+            AFTER UPDATE OR DELETE ON $$ || sch || $$.$$ || tbl || $$ FOR EACH ROW
+            EXECUTE PROCEDURE acq.audit_$$ || sch || $$_$$ || tbl || $$_func ();
+    $$;
+       RETURN TRUE;
+END;
+$creator$ LANGUAGE 'plpgsql';
+
+CREATE OR REPLACE FUNCTION acq.create_acq_lifecycle     ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
+BEGIN
+    EXECUTE $$
+        CREATE OR REPLACE VIEW acq.$$ || sch || $$_$$ || tbl || $$_lifecycle AS
+            SELECT     -1, now() as audit_time, '-' as audit_action, *
+              FROM     $$ || sch || $$.$$ || tbl || $$
+                UNION ALL
+            SELECT     *
+              FROM     acq.$$ || sch || $$_$$ || tbl || $$_history;
+    $$;
+       RETURN TRUE;
+END;
+$creator$ LANGUAGE 'plpgsql';
+
+
+-- The main event
+
+CREATE OR REPLACE FUNCTION acq.create_acq_auditor ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
+BEGIN
+    PERFORM acq.create_acq_seq(sch, tbl);
+    PERFORM acq.create_acq_history(sch, tbl);
+    PERFORM acq.create_acq_func(sch, tbl);
+    PERFORM acq.create_acq_update_trigger(sch, tbl);
+    PERFORM acq.create_acq_lifecycle(sch, tbl);
+    RETURN TRUE;
+END;
+$creator$ LANGUAGE 'plpgsql';
+
+SELECT acq.create_acq_auditor ( 'acq', 'purchase_order' );
+CREATE INDEX acq_po_hist_id_idx            ON acq.acq_purchase_order_history( id );
+
+SELECT acq.create_acq_auditor ( 'acq', 'lineitem' );
+CREATE INDEX acq_lineitem_hist_id_idx            ON acq.acq_lineitem_history( id );
+
+COMMIT;