-- PW-619: refactor material prices

-- create the new price column
DO $$
    BEGIN
        BEGIN
            ALTER TABLE "product-materials" ADD COLUMN price integer NOT NULL DEFAULT 1;
        EXCEPTION
            WHEN duplicate_column THEN RAISE NOTICE 'column price already exists in "product-materials".';
        END;
    END;
$$;


-- populate with default data
UPDATE "product-materials" SET price = 23600 WHERE materialid = 1;
UPDATE "product-materials" SET price = 35600 WHERE materialid = 2;
UPDATE "product-materials" SET price = 79920 WHERE materialid = 3;
UPDATE "product-materials" SET price = 26000 WHERE materialid = 4;


-- drop old views that are no longer used
DROP VIEW IF EXISTS v_materialprice;