Solution for Transactions#195
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am approving your solution because it correctly implements the full transactional flow: creating an order for customer ID = 1, adding an OrderItems row for AwesomeProduct (ProductID = 1, Count = 1), and updating Products.WarehouseAmount inside a single transaction. Functionally, nothing is broken: the inserts and update follow the business rules, and the transaction usage ensures atomicity and consistency. The main concern raised is that you used CURDATE() instead of a fixed literal date like '2023-01-01'; this is not a functional blocker, but it may cause mismatches with strict tests, so I recommend you switch to a hard-coded date in the Orders insert to align perfectly with the task wording. Similarly, if you later change the ordered quantity, it would be more robust to reference that same count in the UPDATE Products statement instead of a hard-coded 1, so they always stay in sync. Overall, your solution demonstrates a solid understanding of transactions and the required schema interactions—only small, non-blocking refinements are suggested.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| START TRANSACTION; | ||
|
|
||
| -- And some data should be created inside the transaction | ||
| INSERT INTO Orders (CustomerID, Date) VALUES(1, CURDATE()); |
There was a problem hiding this comment.
The task explicitly mentions that the order can be created using any date, for example 2023-01-01. Using CURDATE() is logically fine, but to match the requirement and possible tests more strictly, consider replacing CURDATE() with a fixed literal date like '2023-01-01'.
| -- And some data should be created inside the transaction | ||
| INSERT INTO Orders (CustomerID, Date) VALUES(1, CURDATE()); | ||
| INSERT INTO OrderItems (OrderID, ProductID, Count) VALUES(LAST_INSERT_ID(), 1, 1); | ||
| UPDATE Products SET WarehouseAmount = WarehouseAmount - 1 WHERE ID = 1; |
There was a problem hiding this comment.
This update correctly decreases WarehouseAmount for product ID = 1 by the ordered count (1 here), matching the business rule. If you ever change the quantity in the OrderItems insert, consider using the same value here instead of a hard-coded 1 to keep them in sync.
No description provided.