Revision f1faf9a9
Von Bernd Bleßmann vor mehr als 10 Jahren hinzugefügt
sql/Pg-upgrade2/check_bin_belongs_to_wh_trigger.sql | ||
---|---|---|
1 |
-- @tag: check_bin_belongs_to_wh_trigger |
|
2 |
-- @description: Trigger, um sicher zu stellen, dass ein angegebener Lagerplatz auch zum Lager gehört. |
|
3 |
-- @depends: delivery_orders warehouse |
|
4 |
-- @encoding: utf-8 |
|
5 |
|
|
6 |
CREATE FUNCTION check_bin_belongs_to_wh() RETURNS "trigger" |
|
7 |
AS 'BEGIN |
|
8 |
IF NEW.bin_id IS NULL AND NEW.warehouse_id IS NULL THEN |
|
9 |
RETURN NEW; |
|
10 |
END IF; |
|
11 |
IF NEW.bin_id IN (SELECT id FROM bin WHERE warehouse_id = NEW.warehouse_id) THEN |
|
12 |
RETURN NEW; |
|
13 |
ELSE |
|
14 |
RAISE EXCEPTION ''bin (id=%) does not belong to warehouse (id=%).'', NEW.bin_id, NEW.warehouse_id; |
|
15 |
RETURN NULL; |
|
16 |
END IF; |
|
17 |
END;' |
|
18 |
LANGUAGE plpgsql; |
|
19 |
|
|
20 |
|
|
21 |
CREATE TRIGGER check_bin_wh_delivery_order_items_stock BEFORE INSERT OR UPDATE ON delivery_order_items_stock |
|
22 |
FOR EACH ROW EXECUTE PROCEDURE check_bin_belongs_to_wh(); |
|
23 |
|
|
24 |
CREATE TRIGGER check_bin_wh_inventory BEFORE INSERT OR UPDATE ON inventory |
|
25 |
FOR EACH ROW EXECUTE PROCEDURE check_bin_belongs_to_wh(); |
|
26 |
|
|
27 |
CREATE TRIGGER check_bin_wh_parts BEFORE INSERT OR UPDATE ON parts |
|
28 |
FOR EACH ROW EXECUTE PROCEDURE check_bin_belongs_to_wh(); |
Auch abrufbar als: Unified diff
DB-Trigger, um sicher zu stellen, dass ein Lagerplatz auch zum Lager gehört.
Betrifft #2485.