[open-ils-commits] r14367 - in trunk/Open-ILS/src/sql/Pg: . upgrade (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Oct 12 12:24:44 EDT 2009
Author: miker
Date: 2009-10-12 12:24:41 -0400 (Mon, 12 Oct 2009)
New Revision: 14367
Added:
trunk/Open-ILS/src/sql/Pg/upgrade/0031.schema.materialized_billing_summmary_delete_trigger.sql
Modified:
trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
trunk/Open-ILS/src/sql/Pg/080.schema.money.sql
Log:
forward porting 14364: do not use NEW in an ON DELETE trigger, use OLD
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2009-10-12 16:20:56 UTC (rev 14366)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2009-10-12 16:24:41 UTC (rev 14367)
@@ -51,7 +51,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0030'); -- dbs
+INSERT INTO config.upgrade_log (version) VALUES ('0031'); -- miker
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
@@ -562,5 +562,38 @@
( datatype <> 'link' AND fm_class IS NULL ) )
);
+
+-- Some handy functions, based on existing ones, to provide optional ingest normalization
+
+CREATE OR REPLACE FUNCTION public.left_trunc( TEXT, INT ) RETURNS TEXT AS $func$
+ SELECT SUBSTRING($1,$2);
+$func$ LANGUAGE SQL STRICT IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION public.right_trunc( TEXT, INT ) RETURNS TEXT AS $func$
+ SELECT SUBSTRING($1,1,$2);
+$func$ LANGUAGE SQL STRICT IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION public.split_date_range( TEXT ) RETURNS TEXT AS $func$
+ SELECT REGEXP_REPLACE( $1, E'(\\d{4})-(\\d{4})', E'\\1 \\2', 'g' );
+$func$ LANGUAGE SQL STRICT IMMUTABLE;
+
+-- And ... a table in which to register them
+
+CREATE TABLE config.index_normalizer (
+ id SERIAL PRIMARY KEY,
+ name TEXT UNIQUE NOT NULL,
+ func TEXT NOT NULL,
+ param_count INT NOT NULL DEFAULT 0
+);
+
+CREATE TABLE config.metabib_field_index_norm_map (
+ id SERIAL PRIMARY KEY,
+ field INT NOT NULL REFERENCES config.metabib_field (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
+ norm INT NOT NULL REFERENCES config.index_normalizer (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
+ params TEXT,
+ pos INT NOT NULL DEFAULT 0
+);
+
+
COMMIT;
Modified: trunk/Open-ILS/src/sql/Pg/080.schema.money.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/080.schema.money.sql 2009-10-12 16:20:56 UTC (rev 14366)
+++ trunk/Open-ILS/src/sql/Pg/080.schema.money.sql 2009-10-12 16:24:41 UTC (rev 14367)
@@ -374,7 +374,7 @@
SET last_billing_ts = prev_billing.billing_ts,
last_billing_note = prev_billing.note,
last_billing_type = prev_billing.billing_type
- WHERE id = NEW.xact;
+ WHERE id = OLD.xact;
END IF;
IF NOT OLD.voided THEN
Added: trunk/Open-ILS/src/sql/Pg/upgrade/0031.schema.materialized_billing_summmary_delete_trigger.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0031.schema.materialized_billing_summmary_delete_trigger.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0031.schema.materialized_billing_summmary_delete_trigger.sql 2009-10-12 16:24:41 UTC (rev 14367)
@@ -0,0 +1,32 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0031'); -- miker
+
+CREATE OR REPLACE FUNCTION money.materialized_summary_billing_del () RETURNS TRIGGER AS $$
+DECLARE
+ prev_billing money.billing%ROWTYPE;
+ old_billing money.billing%ROWTYPE;
+BEGIN
+ SELECT * INTO prev_billing FROM money.billing WHERE xact = OLD.xact AND NOT voided ORDER BY billing_ts DESC LIMIT 1 OFFSET 1;
+ SELECT * INTO old_billing FROM money.billing WHERE xact = OLD.xact AND NOT voided ORDER BY billing_ts DESC LIMIT 1;
+
+ IF OLD.id = old_billing.id THEN
+ UPDATE money.materialized_billable_xact_summary
+ SET last_billing_ts = prev_billing.billing_ts,
+ last_billing_note = prev_billing.note,
+ last_billing_type = prev_billing.billing_type
+ WHERE id = OLD.xact;
+ END IF;
+
+ IF NOT OLD.voided THEN
+ UPDATE money.materialized_billable_xact_summary
+ SET total_owed = total_owed - OLD.amount,
+ balance_owed = balance_owed + OLD.amount
+ WHERE id = OLD.xact;
+ END IF;
+
+ RETURN OLD;
+END;
+$$ LANGUAGE PLPGSQL;
+
+COMMIT;
More information about the open-ils-commits
mailing list