From: Moritz Bunkus Date: Tue, 15 Jan 2013 14:53:56 +0000 (+0100) Subject: Nach Löschen in customer/vendor via DB-Trigger in contacts, shipto aufräumen X-Git-Tag: release-3.1.0beta1~694 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=7691e04ba5188a2b77761ffff8364728ff6cce52;p=kivitendo-erp.git Nach Löschen in customer/vendor via DB-Trigger in contacts, shipto aufräumen --- diff --git a/sql/Pg-upgrade2/cleanup_after_customer_vendor_deletion.sql b/sql/Pg-upgrade2/cleanup_after_customer_vendor_deletion.sql new file mode 100644 index 000000000..76d68b7a7 --- /dev/null +++ b/sql/Pg-upgrade2/cleanup_after_customer_vendor_deletion.sql @@ -0,0 +1,24 @@ +-- @tag: cleanup_after_customer_vendor_deletion +-- @description: Nach Löschen von Kunden/Lieferanten via Trigger auch Ansprechpersonen/Lieferadressen löschen +-- @depends: release_3_0_0 +-- @charset: utf-8 +CREATE OR REPLACE FUNCTION clean_up_after_customer_vendor_delete() RETURNS trigger AS $$ + BEGIN + DELETE FROM contacts + WHERE cp_cv_id = OLD.id; + + DELETE FROM shipto + WHERE (trans_id = OLD.id) + AND (module = 'CT'); + + RETURN OLD; + END; +$$ LANGUAGE plpgsql; + +CREATE TRIGGER after_delete_customer_trigger +AFTER DELETE ON customer FOR EACH ROW EXECUTE +PROCEDURE clean_up_after_customer_vendor_delete(); + +CREATE TRIGGER after_delete_vendor_trigger +AFTER DELETE ON vendor FOR EACH ROW EXECUTE +PROCEDURE clean_up_after_customer_vendor_delete();