From f8ab4be2ac5b900fe79fc6ac8b748ee30830a382 Mon Sep 17 00:00:00 2001 From: GitHub Gen Changes <> Date: Wed, 19 Jun 2024 07:01:48 +0000 Subject: [PATCH] Added a phone number field to the 'users' table to store user contact information. --- dirs/ecommerce/migrations/20240619070148.sql | 2 + dirs/ecommerce/migrations/atlas.sum | 3 +- dirs/ecommerce/schema.sql | 181 ++++++++++--------- 3 files changed, 95 insertions(+), 91 deletions(-) create mode 100644 dirs/ecommerce/migrations/20240619070148.sql diff --git a/dirs/ecommerce/migrations/20240619070148.sql b/dirs/ecommerce/migrations/20240619070148.sql new file mode 100644 index 0000000..68122f5 --- /dev/null +++ b/dirs/ecommerce/migrations/20240619070148.sql @@ -0,0 +1,2 @@ +-- Modify "users" table +ALTER TABLE `users` ADD COLUMN `phone_number` varchar(15) NULL; diff --git a/dirs/ecommerce/migrations/atlas.sum b/dirs/ecommerce/migrations/atlas.sum index 01e5e8a..18540a1 100644 --- a/dirs/ecommerce/migrations/atlas.sum +++ b/dirs/ecommerce/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:fMiE5LqAjRrhAkhLqmqOpZYumQDQMSkEebG5xSVtNFo= +h1:JPZbznm1BP4Ap0A4eM2yB+xrEXyM7RJ3wxmz1UHePvE= 20230316085611.sql h1:br6W6LPEnnsejlz/7hRm9zthwStCzjN2vZkqVPxlmvo= 20230316090502.sql h1:GfeRjkSeoCt3JVRtLQNa/r50lRfpAPXS7AqTU2ZNFgY= 20230531091333_products_categories.sql h1:59q2M59dV5dJNv4Lyb2TAJz8V6HekgkLn9z4DoL98jA= @@ -13,3 +13,4 @@ h1:fMiE5LqAjRrhAkhLqmqOpZYumQDQMSkEebG5xSVtNFo= 20240319115808_user_is_admin.sql h1:2DLidS3V0AKs8NqPAIUOlJjOUiUvVYPP0stOFSw6gS8= 20240324131640_order_comment.sql h1:TCduwlpoGZn9Zi6v5t3YzaAkeVgQX5fJ96ZbBJbR0MA= 20240617144354.sql h1:mGm4AgdRP4D1QN/FUNB71vqwLi/faoukUxc6OQVppVY= +20240619070148.sql h1:2gYd1ItQwUvPRsazYD5Xmo1iSoCMtpT3iQ16RbIkSFM= diff --git a/dirs/ecommerce/schema.sql b/dirs/ecommerce/schema.sql index 03012ed..f0b9009 100644 --- a/dirs/ecommerce/schema.sql +++ b/dirs/ecommerce/schema.sql @@ -1,109 +1,110 @@ --- Create "users" table +-- Create 'users' table CREATE TABLE `users` ( - `id` int NOT NULL, - `user_name` varchar(255) NOT NULL, - `email` varchar(255) NOT NULL, - `is_admin` bool NULL DEFAULT 0, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (`id`) +`id` int NOT NULL, +`user_name` varchar(255) NOT NULL, +`email` varchar(255) NOT NULL, +`phone_number` varchar(15) NULL, +`is_admin` bool NULL DEFAULT 0, +`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, +PRIMARY KEY (`id`) ) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci; --- Create "categories" table +-- Create 'categories' table CREATE TABLE `categories` ( - `id` int NOT NULL, - `category_name` varchar(255) NOT NULL, - PRIMARY KEY (`id`) +`id` int NOT NULL, +`category_name` varchar(255) NOT NULL, +PRIMARY KEY (`id`) ) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci; --- Create "products" table +-- Create 'products' table CREATE TABLE `products` ( - `id` int NOT NULL, - `product_name` varchar(255) NOT NULL, - `price` decimal(10,2) NOT NULL, - `category_id` int NULL, - 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 +`id` int NOT NULL, +`product_name` varchar(255) NOT NULL, +`price` decimal(10,2) NOT NULL, +`category_id` int NULL, +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 ) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci; --- Create "product_reviews" table +-- Create 'product_reviews' table CREATE TABLE `product_reviews` ( - `id` int NOT NULL, - `product_id` int NOT NULL, - `user_id` int NOT NULL, - `rating` int NOT NULL, - `review_text` text NOT NULL, - PRIMARY KEY (`id`), - INDEX `product_id` (`product_id`), - INDEX `user_id` (`user_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 +`id` int NOT NULL, +`product_id` int NOT NULL, +`user_id` int NOT NULL, +`rating` int NOT NULL, +`review_text` text NOT NULL, +PRIMARY KEY (`id`), +INDEX `product_id` (`product_id`), +INDEX `user_id` (`user_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 ) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci; --- Create "comments" table +-- Create 'comments' table CREATE TABLE `comments` ( - `id` int NOT NULL, - `user_id` int NOT NULL, - `review_id` int NULL, - `parent_comment_id` int NULL, - `comment_text` text NOT NULL, - PRIMARY KEY (`id`), - INDEX `parent_comment_id` (`parent_comment_id`), - INDEX `review_id` (`review_id`), - INDEX `user_id` (`user_id`), - CONSTRAINT `comments_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE, - CONSTRAINT `comments_ibfk_2` FOREIGN KEY (`review_id`) REFERENCES `product_reviews` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE, - CONSTRAINT `comments_ibfk_3` FOREIGN KEY (`parent_comment_id`) REFERENCES `comments` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE +`id` int NOT NULL, +`user_id` int NOT NULL, +`review_id` int NULL, +`parent_comment_id` int NULL, +`comment_text` text NOT NULL, +PRIMARY KEY (`id`), +INDEX `parent_comment_id` (`parent_comment_id`), +INDEX `review_id` (`review_id`), +INDEX `user_id` (`user_id`), +CONSTRAINT `comments_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE, +CONSTRAINT `comments_ibfk_2` FOREIGN KEY (`review_id`) REFERENCES `product_reviews` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE, +CONSTRAINT `comments_ibfk_3` FOREIGN KEY (`parent_comment_id`) REFERENCES `comments` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE ) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci; --- Create "fulfillment_centers" table +-- Create 'fulfillment_centers' table CREATE TABLE `fulfillment_centers` ( - `id` int NOT NULL, - `name` varchar(255) NOT NULL, - `location` varchar(255) NOT NULL, - PRIMARY KEY (`id`) +`id` int NOT NULL, +`name` varchar(255) NOT NULL, +`location` varchar(255) NOT NULL, +PRIMARY KEY (`id`) ) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci; --- Create "inventory" table +-- Create 'inventory' table CREATE TABLE `inventory` ( - `id` int NOT NULL, - `product_id` int NOT NULL, - `fulfillment_center_id` int NOT NULL, - `quantity` int NOT NULL, - PRIMARY KEY (`id`), - 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 +`id` int NOT NULL, +`product_id` int NOT NULL, +`fulfillment_center_id` int NOT NULL, +`quantity` int NOT NULL, +PRIMARY KEY (`id`), +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 ) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci; --- Create "orders" table +-- Create 'orders' table CREATE TABLE `orders` ( - `id` int NOT NULL, - `user_id` int NOT NULL, - `fulfillment_center_id` int NOT NULL, - `total_amount` decimal(10,2) NOT NULL, - `comment` varchar(100) NULL, - PRIMARY KEY (`id`), - INDEX `fulfillment_center_id` (`fulfillment_center_id`), - INDEX `user_id` (`user_id`), - CONSTRAINT `orders_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE, - CONSTRAINT `orders_ibfk_2` FOREIGN KEY (`fulfillment_center_id`) REFERENCES `fulfillment_centers` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE +`id` int NOT NULL, +`user_id` int NOT NULL, +`fulfillment_center_id` int NOT NULL, +`total_amount` decimal(10,2) NOT NULL, +`comment` varchar(100) NULL, +PRIMARY KEY (`id`), +INDEX `fulfillment_center_id` (`fulfillment_center_id`), +INDEX `user_id` (`user_id`), +CONSTRAINT `orders_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE, +CONSTRAINT `orders_ibfk_2` FOREIGN KEY (`fulfillment_center_id`) REFERENCES `fulfillment_centers` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE ) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci; --- Create "order_items" table +-- Create 'order_items' table CREATE TABLE `order_items` ( - `id` int NOT NULL, - `order_id` int NOT NULL, - `product_id` int NOT NULL, - `quantity` int NOT NULL, - `price` decimal(10,2) NOT NULL, - PRIMARY KEY (`id`), - INDEX `order_id` (`order_id`), - INDEX `product_id` (`product_id`), - CONSTRAINT `order_items_ibfk_1` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE, - CONSTRAINT `order_items_ibfk_2` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE +`id` int NOT NULL, +`order_id` int NOT NULL, +`product_id` int NOT NULL, +`quantity` int NOT NULL, +`price` decimal(10,2) NOT NULL, +PRIMARY KEY (`id`), +INDEX `order_id` (`order_id`), +INDEX `product_id` (`product_id`), +CONSTRAINT `order_items_ibfk_1` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE, +CONSTRAINT `order_items_ibfk_2` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE ) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci; --- Create "posts" table +-- Create 'posts' table CREATE TABLE `posts` ( - `id` int NOT NULL, - `user_id` int NOT NULL, - `title` varchar(255) NOT NULL, - `body` text NOT NULL, - PRIMARY KEY (`id`), - INDEX `user_id` (`user_id`), - CONSTRAINT `posts_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE -) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci; +`id` int NOT NULL, +`user_id` int NOT NULL, +`title` varchar(255) NOT NULL, +`body` text NOT NULL, +PRIMARY KEY (`id`), +INDEX `user_id` (`user_id`), +CONSTRAINT `posts_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE +) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci; \ No newline at end of file