From 2e7ce1dbabb6c9a0923c6bed2fb2474534e6eb48 Mon Sep 17 00:00:00 2001 From: Vjekoslav Nikolic Date: Fri, 25 Jul 2025 20:16:24 +0200 Subject: [PATCH] refactor: update prices table structure with a composite primary key --- service/db/psql.sql | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/service/db/psql.sql b/service/db/psql.sql index 8be166d..7e5571d 100644 --- a/service/db/psql.sql +++ b/service/db/psql.sql @@ -104,6 +104,10 @@ CREATE TABLE IF NOT EXISTS prices ( -- Mark regular_price as required if the table already exists ALTER TABLE prices ALTER COLUMN regular_price SET NOT NULL; +ALTER TABLE prices DROP CONSTRAINT IF EXISTS prices_pkey; +ALTER TABLE prices DROP CONSTRAINT IF EXISTS prices_chain_product_id_store_id_price_date_key; +ALTER TABLE prices ADD CONSTRAINT prices_pkey PRIMARY KEY (store_id, chain_product_id, price_date); + -- Prices table to store min/max/avg prices per chain CREATE TABLE IF NOT EXISTS chain_prices ( id SERIAL PRIMARY KEY,