Skip to content

Commit

Permalink
Adding a constraint to ensure that the inventory quantity does not dr…
Browse files Browse the repository at this point in the history
…op below zero, which may succeed or fail depending on current data stored in the inventory table. (#111)

Co-authored-by: GitHub Gen Changes <>
  • Loading branch information
ariga-bot authored Nov 14, 2024
1 parent 1549077 commit 2e4dc6a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions dirs/ecommerce/migrations/20241114131226.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Modify "inventory" table
ALTER TABLE `inventory` ADD CONSTRAINT `inventory_chk_1` CHECK (`quantity` >= 0);
3 changes: 2 additions & 1 deletion dirs/ecommerce/migrations/atlas.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
h1:mQ4os5dvdZVxq9ucRsiEYty95umfc04MMDQfT68e+VI=
h1:NpEy8HM4ZGHgJAWhU65tAJQPaSHCaaEipRBHfZzkY64=
20230316085611.sql h1:br6W6LPEnnsejlz/7hRm9zthwStCzjN2vZkqVPxlmvo=
20230316090502.sql h1:GfeRjkSeoCt3JVRtLQNa/r50lRfpAPXS7AqTU2ZNFgY=
20230531091333_products_categories.sql h1:59q2M59dV5dJNv4Lyb2TAJz8V6HekgkLn9z4DoL98jA=
Expand Down Expand Up @@ -59,3 +59,4 @@ h1:mQ4os5dvdZVxq9ucRsiEYty95umfc04MMDQfT68e+VI=
20241105131055.sql h1:Pa43oRSXYgYlTyRPmz+ifOUdjC37MBxXty/y6GLCaqk=
20241107131023.sql h1:ZCiG0I6S1KZRirv89U4894V9ZBuG6ChLYDuPyWC098c=
20241110130904.sql h1:qRQ+S6KPxiFyp8VxRMkZIFVop3rO1qrS3EJpKz2gjhw=
20241114131226.sql h1:kQjVyuZaEewk+qpzGzSpj2Pwm6mJ6XWci4kBCXXdIY0=
3 changes: 2 additions & 1 deletion dirs/ecommerce/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ CREATE TABLE `inventory` (
INDEX `fulfillment_center_id` (`fulfillment_center_id`),
INDEX `product_id` (`product_id`),
CONSTRAINT `inventory_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE,
CONSTRAINT `inventory_ibfk_2` FOREIGN KEY (`fulfillment_center_id`) REFERENCES `fulfillment_centers` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE
CONSTRAINT `inventory_ibfk_2` FOREIGN KEY (`fulfillment_center_id`) REFERENCES `fulfillment_centers` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE,
CHECK (`quantity` >= 0)
) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT 'Table for managing inventory levels of products at various fulfillment centers';

-- Create 'orders' table
Expand Down

0 comments on commit 2e4dc6a

Please sign in to comment.