Skip to content

Commit

Permalink
Added a CHECK constraint to the 'products' table to ensure that the '…
Browse files Browse the repository at this point in the history
…discount' column value is between 0.00 and 100.00, representing a percentage range from 0% to 100%. (#115)

Co-authored-by: GitHub Gen Changes <>
  • Loading branch information
ariga-bot authored Nov 19, 2024
1 parent 2e4dc6a commit 8ec3751
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/20241119131322.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Modify "products" table
ALTER TABLE `products` ADD CONSTRAINT `products_chk_1` CHECK (`discount` between 0.00 and 100.00);
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:NpEy8HM4ZGHgJAWhU65tAJQPaSHCaaEipRBHfZzkY64=
h1:uJy6QEMl6A/T2FhdxvyTN6NbeiIA0vo4XCM/r+OUmkI=
20230316085611.sql h1:br6W6LPEnnsejlz/7hRm9zthwStCzjN2vZkqVPxlmvo=
20230316090502.sql h1:GfeRjkSeoCt3JVRtLQNa/r50lRfpAPXS7AqTU2ZNFgY=
20230531091333_products_categories.sql h1:59q2M59dV5dJNv4Lyb2TAJz8V6HekgkLn9z4DoL98jA=
Expand Down Expand Up @@ -60,3 +60,4 @@ h1:NpEy8HM4ZGHgJAWhU65tAJQPaSHCaaEipRBHfZzkY64=
20241107131023.sql h1:ZCiG0I6S1KZRirv89U4894V9ZBuG6ChLYDuPyWC098c=
20241110130904.sql h1:qRQ+S6KPxiFyp8VxRMkZIFVop3rO1qrS3EJpKz2gjhw=
20241114131226.sql h1:kQjVyuZaEewk+qpzGzSpj2Pwm6mJ6XWci4kBCXXdIY0=
20241119131322.sql h1:ih7jcLvWFqJnVYDUkMN8wZiKYkgbp65yCTSrzO6pkgg=
3 changes: 2 additions & 1 deletion dirs/ecommerce/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ CREATE TABLE `products` (
PRIMARY KEY (`id`),
INDEX `category_id` (`category_id`),
UNIQUE INDEX `product_name` (`product_name`),
CONSTRAINT `products_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`) ON UPDATE NO ACTION ON DELETE SET NULL
CONSTRAINT `products_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`) ON UPDATE NO ACTION ON DELETE SET NULL,
CHECK (`discount` BETWEEN 0.00 AND 100.00)
) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT 'Table for storing product details, including pricing and category associations';

-- Create 'product_reviews' table
Expand Down

0 comments on commit 8ec3751

Please sign in to comment.