feat: create order with transaction for OrderItems and Products update#204
feat: create order with transaction for OrderItems and Products update#204DRDR92 wants to merge 2 commits into
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am requesting changes because a critical requirement of the task is not yet met: handling the ShopDB lifecycle. The task specifies that any existing ShopDB must be dropped and then recreated using the create-database.sql script, but your task.sql currently only does USE ShopDB; without DROP DATABASE or invoking the creation script. This means the script cannot reliably be run from a fresh or unknown server state as described, which is a blocker for correct task completion.
To fix this, add logic at the top of task.sql (e.g., around line 1–5) to DROP DATABASE ShopDB; if it exists, then recreate it using the schema from create-database.sql (either by sourcing that file or reproducing its statements). Once the database is recreated, your existing order creation, OrderItems insertion, and Products.WarehouseAmount update are structurally sound and correctly use customer ID 1 and product ID 1 with count 1. As a minor improvement, consider a short comment explaining why the Orders insert is outside the transaction while OrderItems and stock updates are inside, to make your transactional reasoning explicit. Overall, your core transactional logic looks good; addressing the database creation requirement will bring the solution fully in line with the task.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| @@ -1,11 +1,15 @@ | |||
| -- Use our database | |||
| USE ShopDB; | |||
| USE ShopDB; | |||
There was a problem hiding this comment.
The task requires that ShopDB be dropped if it already exists and then recreated using the create-database.sql script. Here you only select the database; consider adding the DROP DATABASE ShopDB; and database creation step (or invoking the provided script) so the solution matches the description.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your solution is approved because it correctly recreates the ShopDB database, defines all required tables, and implements the full order flow according to the task requirements. The script cleanly drops and recreates the database, then sets up Products, Customers, Orders, and OrderItems with the necessary columns and relationships [CHECKLIST ITEM #13–#16]. You successfully insert an order for customer ID 1 with the explicit date 2023-01-01, initially without items, and then add an order item for product ID 1 with count 1, linking it via LAST_INSERT_ID() [CHECKLIST ITEM #1–#5, #8–#11]. The transaction that wraps the OrderItems insert and the Products WarehouseAmount decrement ensures the stock update and item creation occur atomically, which matches the business rules [CHECKLIST ITEM #6–#7, #17–#18]. There are no critical blockers or missing core features; the script should run from a clean or dirty state thanks to DROP DATABASE IF EXISTS ShopDB; followed by full schema creation [CHECKLIST ITEM #14, #20]. As a minor note, your use of ON DELETE SET NULL on foreign keys is more flexible than strictly required, but it does not break any requirements and is acceptable. Overall, this is a solid implementation that meets the checklist and functional expectations—well done.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.