[open-ils-commits] r13899 - branches/rel_1_6_0/Open-ILS/src/sql/Pg (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu Aug 20 11:35:46 EDT 2009
Author: miker
Date: 2009-08-20 11:35:43 -0400 (Thu, 20 Aug 2009)
New Revision: 13899
Modified:
branches/rel_1_6_0/Open-ILS/src/sql/Pg/1.4.0.5-1.6.0.0-upgrade-db.sql
branches/rel_1_6_0/Open-ILS/src/sql/Pg/reporter-schema.sql
Log:
backport of r13897: thinko in recent ingest fix
Modified: branches/rel_1_6_0/Open-ILS/src/sql/Pg/1.4.0.5-1.6.0.0-upgrade-db.sql
===================================================================
--- branches/rel_1_6_0/Open-ILS/src/sql/Pg/1.4.0.5-1.6.0.0-upgrade-db.sql 2009-08-20 15:35:29 UTC (rev 13898)
+++ branches/rel_1_6_0/Open-ILS/src/sql/Pg/1.4.0.5-1.6.0.0-upgrade-db.sql 2009-08-20 15:35:43 UTC (rev 13899)
@@ -3857,6 +3857,71 @@
*/
$$;
+SELECT reporter.disable_materialized_simple_record_trigger();
+
+CREATE OR REPLACE FUNCTION reporter.simple_rec_update (r_id BIGINT, deleted BOOL) RETURNS BOOL AS $$
+DECLARE
+ new_data RECORD;
+BEGIN
+
+ DELETE FROM reporter.materialized_simple_record WHERE id = r_id;
+
+ IF NOT deleted THEN
+ INSERT INTO reporter.materialized_simple_record SELECT DISTINCT ON (id) * FROM reporter.old_super_simple_record WHERE id = NEW.record;
+ END IF;
+
+ RETURN TRUE;
+
+END;
+$$ LANGUAGE PLPGSQL;
+
+CREATE OR REPLACE FUNCTION reporter.simple_rec_update (r_id BIGINT) RETURNS BOOL AS $$
+ SELECT reporter.simple_rec_update($1, FALSE);
+$$ LANGUAGE SQL;
+
+CREATE OR REPLACE FUNCTION reporter.simple_rec_delete (r_id BIGINT) RETURNS BOOL AS $$
+ SELECT reporter.simple_rec_update($1, TRUE);
+$$ LANGUAGE SQL;
+
+CREATE OR REPLACE FUNCTION reporter.simple_rec_sync () RETURNS TRIGGER AS $$
+DECLARE
+ r_id BIGINT;
+ deleted BOOL;
+BEGIN
+ IF TG_OP IN ('DELETE') THEN
+ r_id := OLD.record;
+ deleted := TRUE;
+ ELSE
+ r_id := NEW.record;
+ deleted := FALSE;
+ END IF;
+
+ PERFORM reporter.simple_rec_update(r_id, deleted);
+
+ IF deleted THEN
+ RETURN OLD;
+ ELSE
+ RETURN NEW;
+ END IF;
+
+END;
+$$ LANGUAGE PLPGSQL;
+
+CREATE OR REPLACE FUNCTION reporter.simple_rec_bib_sync () RETURNS TRIGGER AS $$
+BEGIN
+ IF NEW.deleted THEN
+ DELETE FROM reporter.materialized_simple_record WHERE id = NEW.id;
+ RETURN NEW;
+ ELSE
+ RETURN NEW;
+ END IF;
+END;
+$$ LANGUAGE PLPGSQL;
+
+CREATE TRIGGER zzz_update_materialized_simple_rec_delete_tgr
+ AFTER UPDATE ON biblio.record_entry
+ FOR EACH ROW EXECUTE PROCEDURE reporter.reporter.simple_rec_bib_sync();
+
COMMIT;
Modified: branches/rel_1_6_0/Open-ILS/src/sql/Pg/reporter-schema.sql
===================================================================
--- branches/rel_1_6_0/Open-ILS/src/sql/Pg/reporter-schema.sql 2009-08-20 15:35:29 UTC (rev 13898)
+++ branches/rel_1_6_0/Open-ILS/src/sql/Pg/reporter-schema.sql 2009-08-20 15:35:43 UTC (rev 13899)
@@ -175,14 +175,12 @@
CREATE VIEW reporter.super_simple_record AS SELECT * FROM reporter.materialized_simple_record;
CREATE OR REPLACE FUNCTION reporter.simple_rec_update (r_id BIGINT, deleted BOOL) RETURNS BOOL AS $$
-DECLARE
- new_data RECORD;
BEGIN
DELETE FROM reporter.materialized_simple_record WHERE id = r_id;
IF NOT deleted THEN
- INSERT INTO reporter.materialized_simple_record SELECT DISTINCT ON (id) * FROM reporter.old_super_simple_record WHERE id = NEW.record;
+ INSERT INTO reporter.materialized_simple_record SELECT DISTINCT ON (id) * FROM reporter.old_super_simple_record WHERE id = r_id;
END IF;
RETURN TRUE;
More information about the open-ils-commits
mailing list