Default to last purchased price and quantity when adding transaction item

This commit is contained in:
2023-07-28 20:23:31 +01:00
parent 4fc1052829
commit 560c162ee1
7 changed files with 104 additions and 58 deletions

View File

@ -0,0 +1,14 @@
CREATE OR REPLACE VIEW item_purchases AS
SELECT
item_id,
transaction_id,
created_at,
store_id,
price,
quantity,
CASE ROW_NUMBER() OVER (PARTITION BY item_id ORDER BY created_at DESC)
WHEN 1 THEN true
ELSE false
END AS is_last_purchase
FROM transaction_items
JOIN transactions USING (transaction_id);