Pflichtenhefte: bendef. Var. beim Löschen des Pflichtenheftes via Trigger löschen
authorMoritz Bunkus <m.bunkus@linet-services.de>
Wed, 4 Feb 2015 15:27:57 +0000 (16:27 +0100)
committerSven Schöling <s.schoeling@linet-services.de>
Thu, 5 Mar 2015 12:42:58 +0000 (13:42 +0100)
sql/Pg-upgrade2/custom_variables_delete_via_trigger_requirement_specs.sql [new file with mode: 0644]

diff --git a/sql/Pg-upgrade2/custom_variables_delete_via_trigger_requirement_specs.sql b/sql/Pg-upgrade2/custom_variables_delete_via_trigger_requirement_specs.sql
new file mode 100644 (file)
index 0000000..da7de2a
--- /dev/null
@@ -0,0 +1,18 @@
+-- @tag: custom_variables_delete_via_trigger_requirement_specs
+-- @description: Benutzerdefinierte Variablen von Pflichtenheften via Trigger löschen
+-- @depends: custom_variables_delete_via_trigger requirement_specs
+CREATE OR REPLACE FUNCTION delete_requirement_spec_custom_variables_trigger() RETURNS trigger AS $$
+  BEGIN
+    DELETE FROM custom_variables WHERE (sub_module = '' OR sub_module IS NULL)
+                                   AND trans_id = OLD.id
+                                   AND (SELECT module FROM custom_variable_configs WHERE id = config_id) = 'RequirementSpecs';
+
+    RETURN OLD;
+  END;
+$$ LANGUAGE plpgsql;
+
+DROP TRIGGER IF EXISTS delete_requirement_spec_custom_variables ON requirement_specs;
+
+CREATE TRIGGER delete_requirement_spec_custom_variables
+BEFORE DELETE ON requirement_specs
+FOR EACH ROW EXECUTE PROCEDURE delete_requirement_spec_custom_variables_trigger();