Nach Löschen in customer/vendor via DB-Trigger in contacts, shipto aufräumen
authorMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 15 Jan 2013 14:53:56 +0000 (15:53 +0100)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Wed, 16 Jan 2013 08:29:45 +0000 (09:29 +0100)
sql/Pg-upgrade2/cleanup_after_customer_vendor_deletion.sql [new file with mode: 0644]

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 (file)
index 0000000..76d68b7
--- /dev/null
@@ -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();