-- Revert master data foreign keys to CASCADE delete (except FCR)
ALTER TABLE nonstock_suppliers
    DROP CONSTRAINT IF EXISTS nonstock_suppliers_nonstock_id_fkey,
    DROP CONSTRAINT IF EXISTS nonstock_suppliers_supplier_id_fkey;

ALTER TABLE nonstock_suppliers
    ADD CONSTRAINT nonstock_suppliers_nonstock_id_fkey FOREIGN KEY (nonstock_id)
        REFERENCES nonstocks (id) ON DELETE CASCADE ON UPDATE CASCADE,
    ADD CONSTRAINT nonstock_suppliers_supplier_id_fkey FOREIGN KEY (supplier_id)
        REFERENCES suppliers (id) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE product_suppliers
    DROP CONSTRAINT IF EXISTS product_suppliers_product_id_fkey,
    DROP CONSTRAINT IF EXISTS product_suppliers_supplier_id_fkey;

ALTER TABLE product_suppliers
    ADD CONSTRAINT product_suppliers_product_id_fkey FOREIGN KEY (product_id)
        REFERENCES products (id) ON DELETE CASCADE ON UPDATE CASCADE,
    ADD CONSTRAINT product_suppliers_supplier_id_fkey FOREIGN KEY (supplier_id)
        REFERENCES suppliers (id) ON DELETE CASCADE ON UPDATE CASCADE;
