From 9c2167dcfefbee4ee55a755901a5d7085981218f Mon Sep 17 00:00:00 2001 From: Anders Gustafsson <34234789+anders-photowall@users.noreply.github.com> Date: Mon, 9 Sep 2024 15:30:35 +0200 Subject: [PATCH] 6101 - add paint_prices table (#416) --- migrations/000.497.sql | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 migrations/000.497.sql diff --git a/migrations/000.497.sql b/migrations/000.497.sql new file mode 100644 index 0000000..3f1e418 --- /dev/null +++ b/migrations/000.497.sql @@ -0,0 +1,23 @@ +-- 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;