Fehler #505 » remove_custom_variables_validity_after_deleting_parts.sql
1 |
-- @tag: remove_custom_variables_validity_after_deleting_parts
|
---|---|
2 |
-- @description: Beim Löschen von Artikeln auch custom_variables_validity löschen
|
3 |
-- @depends: release_3_6_1
|
4 |
|
5 |
-- remove any orphaned entries
|
6 |
DELETE FROM custom_variables_validity |
7 |
WHERE trans_id NOT IN ( |
8 |
SELECT id |
9 |
FROM parts |
10 |
);
|
11 |
|
12 |
CREATE OR REPLACE FUNCTION public.delete_custom_variables_trigger() |
13 |
RETURNS trigger |
14 |
LANGUAGE plpgsql |
15 |
AS $$ |
16 |
BEGIN
|
17 |
IF (TG_TABLE_NAME IN ('orderitems', 'delivery_order_items', 'invoice')) THEN |
18 |
PERFORM delete_custom_variables_with_sub_module('IC', TG_TABLE_NAME, old.id); |
19 |
END IF; |
20 |
|
21 |
IF (TG_TABLE_NAME = 'parts') THEN |
22 |
PERFORM delete_custom_variables_with_sub_module('IC', '', old.id); |
23 |
DELETE FROM custom_variables_validity WHERE trans_id = old.id; |
24 |
END IF; |
25 |
|
26 |
IF (TG_TABLE_NAME IN ('customer', 'vendor')) THEN |
27 |
PERFORM delete_custom_variables_with_sub_module('CT', '', old.id); |
28 |
END IF; |
29 |
|
30 |
IF (TG_TABLE_NAME = 'contacts') THEN |
31 |
PERFORM delete_custom_variables_with_sub_module('Contacts', '', old.cp_id); |
32 |
END IF; |
33 |
|
34 |
IF (TG_TABLE_NAME = 'project') THEN |
35 |
PERFORM delete_custom_variables_with_sub_module('Projects', '', old.id); |
36 |
END IF; |
37 |
|
38 |
RETURN old; |
39 |
END; |
40 |
$$; |