Skip to content

Commit

Permalink
Added a CHECK constraint to ensure that the 'rating' in the 'product_…
Browse files Browse the repository at this point in the history
…reviews' table is within the range of 1 to 5. (#144)

Co-authored-by: GitHub Gen Changes <>
  • Loading branch information
ariga-bot authored Jan 23, 2025
1 parent 2ac7fdc commit 491bc19
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/20250123131157.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Modify "product_reviews" table
ALTER TABLE `product_reviews` ADD CONSTRAINT `product_reviews_chk_1` CHECK (`rating` between 1 and 5);
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:qUsV8m7kQlXC4YC/G1sDfxsE9LPgKNyNy7O+/X0UBpE=
h1:DwJL5vSGojPGgDsgArTBRR/hoMDbfMGX8s/NjwJHZkw=
20230316085611.sql h1:br6W6LPEnnsejlz/7hRm9zthwStCzjN2vZkqVPxlmvo=
20230316090502.sql h1:GfeRjkSeoCt3JVRtLQNa/r50lRfpAPXS7AqTU2ZNFgY=
20230531091333_products_categories.sql h1:59q2M59dV5dJNv4Lyb2TAJz8V6HekgkLn9z4DoL98jA=
Expand Down Expand Up @@ -71,3 +71,4 @@ h1:qUsV8m7kQlXC4YC/G1sDfxsE9LPgKNyNy7O+/X0UBpE=
20250107131148.sql h1:myfTSveM0wrY/UypJW3R/kZX8Dz4fW6w5/kAuYLncWM=
20250112130920.sql h1:apmP+t1Zki0aUrUquK4m6DKnH6tGrSa99Ep+LXNjz8k=
20250114131013.sql h1:uHxFLNR7VUSQJ20e4LdjWYTkuZ7yibVTVeCpYshlHAM=
20250123131157.sql h1:oWdCizC0eU0GN195MTPHTgs9mpkl0D18E1hV0NoNy1s=
3 changes: 2 additions & 1 deletion dirs/ecommerce/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ CREATE TABLE `product_reviews` (
INDEX `user_id` (`user_id`),
UNIQUE INDEX `user_product_review` (`user_id`, `product_id`),
CONSTRAINT `product_reviews_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE,
CONSTRAINT `product_reviews_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE
CONSTRAINT `product_reviews_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE,
CHECK (`rating` BETWEEN 1 AND 5)
) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT 'Table for storing reviews of products by users';

-- Create 'fulfillment_centers' table
Expand Down

0 comments on commit 491bc19

Please sign in to comment.