Skip to content

Solution v1#129

Open
whatislavx wants to merge 3 commits into
mate-academy:mainfrom
whatislavx:devops/databases
Open

Solution v1#129
whatislavx wants to merge 3 commits into
mate-academy:mainfrom
whatislavx:devops/databases

Conversation

@whatislavx

Copy link
Copy Markdown

No description provided.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

This requires changes as the submission doesn't fully meet the core requirements. You've made a good start on normalizing the database, but the current schema is not yet in Third Normal Form (3NF), and a required setup command is missing.

Here are the key issues to address:

  1. Database Normalization (Not 3NF): The schema has a few issues preventing it from being in 3NF. The WarehouseAmount column belongs in a table linking products and warehouses, not in WareHouses itself. Additionally, storing ProductName directly creates redundancy, and the CountryID column creates a transitive dependency. Please create a separate Products table and adjust the relationships to resolve this.
  2. Missing DROP DATABASE Statement: The script needs to include DROP DATABASE IF EXISTS ShopDB; at the very beginning to ensure it can be run multiple times without errors.

Please correct the table structure to be 3NF-compliant and add the missing command. After that, remember to update your INSERT statements to match the new schema.


✨ 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. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread task.sql Outdated
CREATE TABLE WareHouses (
ID INT,
ProductName VARCHAR(50),
WarehouseAmount INT,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The WarehouseAmount column doesn't belong in this table. The amount of stock is a property of a specific product within a warehouse, not a property of the warehouse itself. To properly normalize the database, this information should be in a table that links products to warehouses.

Comment thread task.sql Outdated
-- Populate test data
CREATE TABLE ProductInventory (
ID INT,
ProductName VARCHAR(50),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Storing the product name directly in this table leads to data redundancy. To achieve proper normalization, you should create a separate Products table to store product information and then reference products here using a foreign key (e.g., ProductID).

Comment thread task.sql Outdated
ID INT,
ProductName VARCHAR(50),
WarehouseID INT,
CountryID INT,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This CountryID column appears to create a transitive dependency, which violates the third normal form (3NF). If a warehouse is located in a specific country, the CountryID should be in the WareHouses table. A transitive dependency exists when a non-key attribute (CountryID) depends on another non-key attribute (WarehouseID).

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Great job separating the warehouse information into its own table! You're making good progress toward normalization. However, this requires a few more changes before it's ready, as the current schema violates Third Normal Form (3NF) and the script contains INSERT statements that will cause errors.

Here are the key issues to address:

  1. Normalization: To achieve 3NF, you'll need to create a separate Products table to avoid redundancy with ProductName. Additionally, the CountryID column should be moved from ProductInventory to the WareHouses table to resolve the transitive dependency.
  2. SQL Errors: The INSERT statement for WareHouses will fail because it references a WarehouseAmount column that doesn't exist in that table. Conversely, the INSERT for ProductInventory is missing a value for its WarehouseAmount column.

Please correct these issues to ensure the schema is fully normalized and the script can run without errors.


✨ 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. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread task.sql Outdated

CREATE TABLE ProductInventory (
ID INT,
ProductName VARCHAR(50),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ProductName column introduces redundancy. To normalize the schema to 3NF, product information should be in a separate Products table. This ProductInventory table would then use a ProductID as a foreign key.

Comment thread task.sql Outdated
WarehouseAmount INT,
WarehouseName VARCHAR(50),
WarehouseAddress VARCHAR(50),
CountryID INT,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This CountryID column creates a transitive dependency, which violates 3NF. A warehouse is located in a country, so CountryID should logically be part of the WareHouses table, not here. The dependency chain ProductInventory -> Warehouse -> Country should be established by linking these tables correctly.

Comment thread task.sql Outdated
VALUES (1, 'AwersomeProduct', 2, 'Warehouse-1', 'City-1, Street-1',1);
INSERT INTO ProductInventory (ID,ProductName,WarehouseAmount,WarehouseName,WarehouseAddress,CountryID)
VALUES (2, 'AwersomeProduct', 5, 'Warehouse-2', 'City-2, Street-2',2);
INSERT INTO WareHouses (ID, WarehouseAmount, WarehouseName, WarehouseAddress)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This INSERT statement will fail. You are trying to insert a value for WarehouseAmount, but the WareHouses table definition (lines 12-17) does not include this column.

Comment thread task.sql Outdated
VALUES (1, 100, 'Main Warehouse', 'Address 1'),
(2, 200, 'Backup Warehouse', 'Address 2');

INSERT INTO ProductInventory (ID, ProductName, CountryID, WarehouseID)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This INSERT statement is missing a value for the WarehouseAmount column, which is defined in the ProductInventory table on line 23. The quantity of a product in a warehouse is essential data that should be included here.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Great job on this iteration! You've successfully normalized the database schema to the Third Normal Form and fixed all the previous syntax issues, which is excellent progress. I am approving your solution as an educational override so you can move forward, but there's one important logical issue to address in your test data. In your task.sql file, you've inserted 'AwersomeProduct' into the Products table twice with two different IDs. The goal of normalization is to avoid this kind of redundancy. To fix this, you should insert each unique product only once, and then have both entries in the ProductInventory table reference that single ProductID. Keep up the great work!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Comment thread task.sql

INSERT INTO Products (ID, ProductName)
VALUES (1, 'AwersomeProduct'),
(2, 'AwersomeProduct');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've correctly created the Products table to normalize the data. However, by inserting 'AwersomeProduct' twice with two different IDs, you are re-introducing data redundancy. The purpose of this table is to have a single entry for each unique product. You should insert 'AwersomeProduct' only once.

Comment thread task.sql
VALUES (2, 'AwersomeProduct', 5, 'Warehouse-2', 'City-2, Street-2',2);
INSERT INTO ProductInventory (ID, ProductID, WarehouseID, WarehouseAmount)
VALUES (1, 1, 1, 100),
(2, 2, 2, 200);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following the correction to avoid duplicate products in the Products table, this row should be updated to use the single ProductID for 'AwersomeProduct' to indicate that the same product is in this second warehouse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants