-- P5-4494: remove all contract customer discounts except general discount

ALTER TABLE contract_customers
    ADD COLUMN discount INTEGER DEFAULT 0;

UPDATE contract_customers SET discount = (
    SELECT discount FROM contract_customers_discounts
    WHERE contractcustomerid = contract_customers.contractcustomerid
    AND productgroupid IS NULL AND materialid IS NULL
);

DROP TABLE contract_customers_discounts;
