Skip to content

Commit

Permalink
feat(order): add missing total price
Browse files Browse the repository at this point in the history
this will handle showing the accurate price in case the tutor change it
over time
  • Loading branch information
Veirt committed Dec 5, 2024
1 parent d909377 commit a3c332a
Show file tree
Hide file tree
Showing 8 changed files with 1,135 additions and 3 deletions.
12 changes: 12 additions & 0 deletions drizzle/0014_married_jocasta.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ALTER TABLE "orders" ADD COLUMN "price" integer;

UPDATE orders
SET price = subquery.total_price
FROM (
SELECT o.id AS order_id, o.total_hours, t.hourly_rate, (o.total_hours * t.hourly_rate) AS total_price
FROM orders o
JOIN tutories t ON t.id = o."tutoriesId"
) AS subquery
WHERE orders.id = subquery.order_id;

ALTER TABLE "orders" ALTER COLUMN "price" SET NOT NULL;
Loading

0 comments on commit a3c332a

Please sign in to comment.