[open-ils-commits] r15484 - trunk/Open-ILS/src/sql/Pg/upgrade (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Feb 9 13:00:15 EST 2010
Author: erickson
Date: 2010-02-09 13:00:11 -0500 (Tue, 09 Feb 2010)
New Revision: 15484
Added:
trunk/Open-ILS/src/sql/Pg/upgrade/0087.schema.audit_functions_atomized.sql
Log:
insert 'schema' into upgrade script name
Copied: trunk/Open-ILS/src/sql/Pg/upgrade/0087.schema.audit_functions_atomized.sql (from rev 15481, trunk/Open-ILS/src/sql/Pg/upgrade/0087.audit_functions_atomized.sql)
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0087.schema.audit_functions_atomized.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0087.schema.audit_functions_atomized.sql 2010-02-09 18:00:11 UTC (rev 15484)
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2009 Equinox Software, Inc.
+ * Joe Atzberger
+ *
+ * Released under GNU General Public License version 2
+ */
+
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0087'); -- atz
+
+CREATE FUNCTION auditor.create_auditor_seq ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
+BEGIN
+ EXECUTE $$
+ CREATE SEQUENCE auditor.$$ || sch || $$_$$ || tbl || $$_pkey_seq;
+ $$;
+ RETURN TRUE;
+END;
+$creator$ LANGUAGE 'plpgsql';
+
+CREATE FUNCTION auditor.create_auditor_history ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
+BEGIN
+ EXECUTE $$
+ CREATE TABLE auditor.$$ || 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 FUNCTION auditor.create_auditor_func ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
+BEGIN
+ EXECUTE $$
+ CREATE FUNCTION auditor.audit_$$ || sch || $$_$$ || tbl || $$_func ()
+ RETURNS TRIGGER AS $func$
+ BEGIN
+ INSERT INTO auditor.$$ || sch || $$_$$ || tbl || $$_history
+ SELECT nextval('auditor.$$ || sch || $$_$$ || tbl || $$_pkey_seq'),
+ now(),
+ SUBSTR(TG_OP,1,1),
+ OLD.*;
+ RETURN NULL;
+ END;
+ $func$ LANGUAGE 'plpgsql';
+ $$;
+ RETURN TRUE;
+END;
+$creator$ LANGUAGE 'plpgsql';
+
+CREATE FUNCTION auditor.create_auditor_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 auditor.audit_$$ || sch || $$_$$ || tbl || $$_func ();
+ $$;
+ RETURN TRUE;
+END;
+$creator$ LANGUAGE 'plpgsql';
+
+CREATE FUNCTION auditor.create_auditor_lifecycle ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
+BEGIN
+ EXECUTE $$
+ CREATE VIEW auditor.$$ || sch || $$_$$ || tbl || $$_lifecycle AS
+ SELECT -1, now() as audit_time, '-' as audit_action, *
+ FROM $$ || sch || $$.$$ || tbl || $$
+ UNION ALL
+ SELECT *
+ FROM auditor.$$ || sch || $$_$$ || tbl || $$_history;
+ $$;
+ RETURN TRUE;
+END;
+$creator$ LANGUAGE 'plpgsql';
+
+DROP FUNCTION IF EXISTS auditor.create_auditor (TEXT, TEXT); -- Besides this line and the 0087 INSERT, the rest of this file is 900.audit-functions.sql
+
+-- The main event
+
+CREATE FUNCTION auditor.create_auditor ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
+BEGIN
+ PERFORM auditor.create_auditor_seq(sch, tbl);
+ PERFORM auditor.create_auditor_history(sch, tbl);
+ PERFORM auditor.create_auditor_func(sch, tbl);
+ PERFORM auditor.create_auditor_update_trigger(sch, tbl);
+ PERFORM auditor.create_auditor_lifecycle(sch, tbl);
+ RETURN TRUE;
+END;
+$creator$ LANGUAGE 'plpgsql';
+
+COMMIT;
+
Property changes on: trunk/Open-ILS/src/sql/Pg/upgrade/0087.schema.audit_functions_atomized.sql
___________________________________________________________________
Name: svn:mergeinfo
+ /trunk/Open-ILS/src/sql/Pg/upgrade/0087.audit_functions_atomized.sql:10932,10935
More information about the open-ils-commits
mailing list