Revision 349cde39
Von Bernd Bleßmann vor mehr als 4 Jahren hinzugefügt
sql/Pg-upgrade2/delete_cvars_on_trans_deletion_add_shipto.sql | ||
---|---|---|
1 |
-- @tag: delete_cvars_on_trans_deletion_add_shipto |
|
2 |
-- @description: Löschen von benutzerdefinierten Variablen via Triggerfunktionen auch für shipto |
|
3 |
-- @depends: delete_cvars_on_trans_deletion delete_cvars_on_trans_deletion_fix1 |
|
4 |
|
|
5 |
-- 1.6 Alle benutzerdefinierten Variablen löschen, für die es keine |
|
6 |
-- Einträge in shipto mehr gibt. |
|
7 |
DELETE FROM custom_variables WHERE EXISTS |
|
8 |
(SELECT cv.id FROM custom_variables cv LEFT JOIN custom_variable_configs cvc ON (cv.config_id = cvc.id) |
|
9 |
WHERE module LIKE 'ShipTo' |
|
10 |
AND NOT EXISTS (SELECT shipto_id FROM shipto WHERE shipto_id = cv.trans_id)); |
|
11 |
|
|
12 |
|
|
13 |
-- 2.2. Nun die Funktionen, die als Trigger aufgerufen wird und die |
|
14 |
-- entscheidet, wie genau zu löschen ist: |
|
15 |
CREATE OR REPLACE FUNCTION delete_custom_variables_trigger() |
|
16 |
RETURNS TRIGGER AS $$ |
|
17 |
BEGIN |
|
18 |
IF (TG_TABLE_NAME IN ('orderitems', 'delivery_order_items', 'invoice')) THEN |
|
19 |
PERFORM delete_custom_variables_with_sub_module('IC', TG_TABLE_NAME, old.id); |
|
20 |
END IF; |
|
21 |
|
|
22 |
IF (TG_TABLE_NAME = 'parts') THEN |
|
23 |
PERFORM delete_custom_variables_with_sub_module('IC', '', 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 |
IF (TG_TABLE_NAME = 'shipto') THEN |
|
39 |
PERFORM delete_custom_variables_with_sub_module('ShipTo', '', old.shipto_id); |
|
40 |
END IF; |
|
41 |
|
|
42 |
RETURN old; |
|
43 |
END; |
|
44 |
$$ LANGUAGE plpgsql; |
|
45 |
|
|
46 |
-- 3. Die eigentlichen Trigger erstellen: |
|
47 |
|
|
48 |
-- 3.9. shipto |
|
49 |
DROP TRIGGER IF EXISTS shipto_delete_custom_variables_after_deletion ON shipto; |
|
50 |
|
|
51 |
CREATE TRIGGER shipto_delete_custom_variables_after_deletion |
|
52 |
AFTER DELETE ON shipto |
|
53 |
FOR EACH ROW EXECUTE PROCEDURE delete_custom_variables_trigger(); |
Auch abrufbar als: Unified diff
CVars: Einträge beim Löschen dazugehöriger Lieferadressen automatisch löschen