-- Change so paint price is per bucket size instead of per liter
ALTER TABLE prices_other_products DROP COLUMN IF EXISTS paint_price_per_liter;

DROP TABLE IF EXISTS paint_prices;

CREATE TABLE paint_prices (
    liters           NUMERIC NOT NULL,
    market_id        INT REFERENCES markets (id) NOT NULL,
    price            NUMERIC NOT NULL CHECK (price > 0),
    created          timestamp with time zone NOT NULL DEFAULT now(),
    updated          timestamp with time zone DEFAULT NULL,
    PRIMARY KEY (liters, market_id)
);

CREATE TRIGGER updated_timestamp BEFORE UPDATE ON paint_prices FOR EACH ROW EXECUTE PROCEDURE updated_timestamp();

-- for each market in markets, add a row for each paint size
INSERT INTO paint_prices (liters, market_id, price)
  SELECT liters, markets.id, 19 FROM paint_primer_sizes CROSS JOIN markets WHERE paint_primer_id=1 ORDER BY markets.id, liters;

-- set some made up prices for the different paint sizes
UPDATE paint_prices SET price = 99 WHERE liters = 0.9;
UPDATE paint_prices SET price = 199 WHERE liters = 2.7;
