adding "lifecyle" view to each audited table
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 25 Aug 2005 18:48:53 +0000 (18:48 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 25 Aug 2005 18:48:53 +0000 (18:48 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@1735 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/sql/Pg/900.audit-tables.sql

index f7e14e8..5becb97 100644 (file)
@@ -9,7 +9,7 @@ BEGIN
        EXECUTE $$
                        CREATE TABLE auditor.$$ || sch || $$_$$ || tbl || $$_history (
                                audit_time      TIMESTAMP WITH TIME ZONE        NOT NULL,
-                               audit_action    CHAR(1)                         NOT NULL,
+                               audit_action    "char"                          NOT NULL,
                                LIKE $$ || sch || $$.$$ || tbl || $$
                        );
        $$;
@@ -30,6 +30,15 @@ BEGIN
                                AFTER UPDATE OR DELETE ON $$ || sch || $$.$$ || tbl || $$ FOR EACH ROW
                                EXECUTE PROCEDURE auditor.audit_$$ || sch || $$_$$ || tbl || $$_func ();
        $$;
+
+       EXECUTE $$
+                       CREATE VIEW auditor.$$ || sch || $$_$$ || tbl || $$_lifecycle AS
+                               SELECT  now() as audit_time, 'C' as audit_action, *
+                                 FROM  $$ || sch || $$.$$ || tbl || $$
+                                       UNION ALL
+                               SELECT  *
+                                 FROM  auditor.$$ || sch || $$_$$ || tbl || $$_history;
+       $$;
        RETURN TRUE;
 END;
 $creator$ LANGUAGE 'plpgsql';