Solution for Database normalization#193
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am requesting changes because one explicit requirement from the task is not met, and it can break rerunning the script. The task states that if the ShopDB database already exists, it must be dropped with DROP DATABASE ShopDB; before creating it; in your script you only have CREATE DATABASE ShopDB; and USE ShopDB; (near the top of task.sql), so executing the file a second time on the same server will fail. To fix this, add a line like DROP DATABASE IF EXISTS ShopDB; immediately before CREATE DATABASE ShopDB; so the script is idempotent and always runs cleanly from scratch.
Aside from that, your normalization work is solid: you correctly split the data into Countries, Warehouses, Products, and ProductInventory with appropriate foreign keys, and you preserved the original logical test data (one product, two warehouses, matching countries and quantities). As a minor, optional improvement, you might consider adding AUTO_INCREMENT to your ID columns so you don’t have to manage IDs manually, but this is not required by the task. Once you add the missing DROP DATABASE step, your solution will satisfy the critical requirements and should be in good shape.
✨ 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
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am approving your solution because it meets the functional and structural requirements of the task: the schema is correctly normalized into Countries, Warehouses, Products, and ProductInventory, and your INSERT statements reproduce the intended test scenario within ShopDB. The database is created and used as required, and the relationships between products and warehouses via ProductInventory allow multiple warehouses and quantities per product, which aligns with the design goals.
The only remaining concern is non-blocking: your use of DROP DATABASE ShopDB; on line 3 will raise an error if ShopDB does not exist, which means the script is not fully idempotent for reruns. As an improvement (but not a requirement for passing), you could change that line to:
DROP DATABASE IF EXISTS ShopDB;This would make the script safer to execute in fresh environments and when rerun multiple times. Overall, you’ve done a solid job implementing the normalized schema and data inserts, so your work is accepted; consider the IF EXISTS tweak as a robustness enhancement for future scripts.
✨ 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,3 +1,7 @@ | |||
| -- Delete ShopDB if it exists | |||
|
|
|||
| DROP DATABASE ShopDB; | |||
There was a problem hiding this comment.
Right now you use a plain DROP DATABASE ShopDB;. While this matches the wording in the task, it will throw an error if ShopDB doesn’t exist when you run the script; consider changing it to DROP DATABASE IF EXISTS ShopDB; so the script can be rerun safely, as mentioned in the previous review.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your solution is approved based on the current task.sql implementation. You successfully normalized the original ProductInventory table into separate Countries, Warehouses, Products, and ProductInventory tables, which removes repeating attributes and transitive dependencies and brings the design into third normal form [CHECKLIST ITEM #2, #8, #12]. The ProductInventory table correctly models quantities per product per warehouse, allowing multiple warehouses to hold different quantities of the same product [CHECKLIST ITEM #3]. You also correctly drop and recreate ShopDB, then use standard MySQL DDL with primary keys and foreign keys that have appropriate ON DELETE behavior, which aligns with the compatibility and lifecycle requirements [CHECKLIST ITEM #1, #4, #7, #11, #14]. Finally, your INSERT statements recreate the intended test scenario (two countries, two warehouses, one product, and quantities of 2 and 5 in different warehouses), so it should integrate smoothly with the provided test script [CHECKLIST ITEM #5, #6]. Overall, this is clean, well-structured SQL that meets the task’s goals—nice work continuing to apply good normalization and constraint practices.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.