Benutzerdefinierte Variablen via Trigger löschen Bugfix
authorMoritz Bunkus <m.bunkus@linet-services.de>
Wed, 12 Nov 2014 11:01:09 +0000 (12:01 +0100)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Wed, 12 Nov 2014 11:30:28 +0000 (12:30 +0100)
Die ID-Spalte heißt in der contacts-Tabelle cp_id und nicht id.

sql/Pg-upgrade2/delete_cvars_on_trans_deletion_fix1.sql [new file with mode: 0644]

diff --git a/sql/Pg-upgrade2/delete_cvars_on_trans_deletion_fix1.sql b/sql/Pg-upgrade2/delete_cvars_on_trans_deletion_fix1.sql
new file mode 100644 (file)
index 0000000..291cc5f
--- /dev/null
@@ -0,0 +1,32 @@
+-- @tag: delete_cvars_on_trans_deletion_fix1
+-- @description: Bugfix 1 für das Löschen von benutzerdefinierten Variablen via Triggerfunktionen
+-- @depends: delete_cvars_on_trans_deletion
+
+-- 2.2. Nun die Funktionen, die als Trigger aufgerufen wird und die
+-- entscheidet, wie genau zu löschen ist:
+CREATE OR REPLACE FUNCTION delete_custom_variables_trigger()
+RETURNS TRIGGER AS $$
+  BEGIN
+    IF (TG_TABLE_NAME IN ('orderitems', 'delivery_order_items', 'invoice')) THEN
+      PERFORM delete_custom_variables_with_sub_module('IC', TG_TABLE_NAME, old.id);
+    END IF;
+
+    IF (TG_TABLE_NAME = 'parts') THEN
+      PERFORM delete_custom_variables_with_sub_module('IC', '', old.id);
+    END IF;
+
+    IF (TG_TABLE_NAME IN ('customer', 'vendor')) THEN
+      PERFORM delete_custom_variables_with_sub_module('CT', '', old.id);
+    END IF;
+
+    IF (TG_TABLE_NAME = 'contacts') THEN
+      PERFORM delete_custom_variables_with_sub_module('Contacts', '', old.cp_id);
+    END IF;
+
+    IF (TG_TABLE_NAME = 'project') THEN
+      PERFORM delete_custom_variables_with_sub_module('Projects', '', old.id);
+    END IF;
+
+    RETURN old;
+  END;
+$$ LANGUAGE plpgsql;