๐Ÿ–ฅ๏ธ

Real incidents need a real screen.

Open senioreng.dev on your laptop for the full experience.

Pull Request #3104

Add CASCADE DELETE to order_items โ€” clean up when orders are deleted

Automates order_item cleanup by adding an ON DELETE CASCADE constraint so that deleting an order automatically removes its associated line items.

Ready to merge
db/migration/V18_add_cascade_delete_order_items.sql+15 additions
1
+ -- order_items table (context โ€” existing structure)
2
+ -- id BIGINT PRIMARY KEY
3
+ -- order_id BIGINT REFERENCES orders(id) -- FK to parent order
4
+ -- product_id BIGINT REFERENCES products(id) -- FK to product catalog
5
+ -- quantity INT
6
+ -- price NUMERIC(10,2)
7
+
8
+ -- Goal: clean up order_items when the parent order is removed
9
+
10
+ ALTER TABLE order_items
11
+ DROP CONSTRAINT order_items_product_id_fkey,
12
+ ADD CONSTRAINT order_items_product_id_fkey
13
+ FOREIGN KEY (product_id)
14
+ REFERENCES products(id)
15
+ ON DELETE CASCADE;
PE

priya_eng

Approved review

Looks good, cascade is there. This will automate the cleanup nicely.

Review comments ยท db/migration/V18_add_cascade_delete_order_items.sql