-- @tag: oe_delivery_orders_foreign_keys
-- @description: Fremdschlüsseldefinitionen für oe und delivery_orders
-- @depends: release_3_0_0
--- @charset: utf-8
ALTER TABLE oe ALTER COLUMN department_id DROP DEFAULT;
UPDATE oe SET cp_id = NULL WHERE (cp_id IS NOT NULL) AND (cp_id NOT IN (SELECT cp_id FROM contacts));
ALTER TABLE oe ADD FOREIGN KEY (delivery_customer_id) REFERENCES customer (id);
ALTER TABLE oe ADD FOREIGN KEY (delivery_vendor_id) REFERENCES vendor (id);
ALTER TABLE oe ADD FOREIGN KEY (department_id) REFERENCES department (id);
-ALTER TABLE oe ADD FOREIGN KEY (employee_id) REFERENCES employee (id);
ALTER TABLE oe ADD FOREIGN KEY (language_id) REFERENCES language (id);
ALTER TABLE oe ADD FOREIGN KEY (payment_id) REFERENCES payment_terms (id);
ALTER TABLE oe ADD FOREIGN KEY (shipto_id) REFERENCES shipto (shipto_id);