From 83e6ff519bcdcffe1c6be65f5054ef33969e9b80 Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Wed, 15 May 2024 21:13:05 +0400 Subject: [PATCH 01/13] remove data dump from schema file --- .../{dump/cafe.sql => cafe_schema.sql} | 124 ++---------------- 1 file changed, 10 insertions(+), 114 deletions(-) rename resources/database/{dump/cafe.sql => cafe_schema.sql} (68%) diff --git a/resources/database/dump/cafe.sql b/resources/database/cafe_schema.sql similarity index 68% rename from resources/database/dump/cafe.sql rename to resources/database/cafe_schema.sql index 15e4128..3229df5 100644 --- a/resources/database/dump/cafe.sql +++ b/resources/database/cafe_schema.sql @@ -15,6 +15,14 @@ /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; +-- +-- Current Database: `cafe` +-- + +CREATE DATABASE /*!32312 IF NOT EXISTS*/ `cafe` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci */; + +USE `cafe`; + -- -- Table structure for table `administrator` -- @@ -32,15 +40,6 @@ CREATE TABLE `administrator` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Dumping data for table `administrator` --- - -LOCK TABLES `administrator` WRITE; -/*!40000 ALTER TABLE `administrator` DISABLE KEYS */; -/*!40000 ALTER TABLE `administrator` ENABLE KEYS */; -UNLOCK TABLES; - -- -- Table structure for table `client` -- @@ -62,15 +61,6 @@ CREATE TABLE `client` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Dumping data for table `client` --- - -LOCK TABLES `client` WRITE; -/*!40000 ALTER TABLE `client` DISABLE KEYS */; -/*!40000 ALTER TABLE `client` ENABLE KEYS */; -UNLOCK TABLES; - -- -- Table structure for table `comment` -- @@ -95,15 +85,6 @@ CREATE TABLE `comment` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Dumping data for table `comment` --- - -LOCK TABLES `comment` WRITE; -/*!40000 ALTER TABLE `comment` DISABLE KEYS */; -/*!40000 ALTER TABLE `comment` ENABLE KEYS */; -UNLOCK TABLES; - -- -- Table structure for table `district` -- @@ -120,16 +101,6 @@ CREATE TABLE `district` ( ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Dumping data for table `district` --- - -LOCK TABLES `district` WRITE; -/*!40000 ALTER TABLE `district` DISABLE KEYS */; -INSERT INTO `district` VALUES (4,'Black River'),(3,'Flacq'),(6,'Grand Port'),(1,'Moka'),(8,'Pamplemousses'),(9,'Plaines Wilhems'),(2,'Port Louis'),(7,'Riviere du Rempart'),(5,'Savanne'); -/*!40000 ALTER TABLE `district` ENABLE KEYS */; -UNLOCK TABLES; - -- -- Table structure for table `order` -- @@ -153,15 +124,6 @@ CREATE TABLE `order` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Dumping data for table `order` --- - -LOCK TABLES `order` WRITE; -/*!40000 ALTER TABLE `order` DISABLE KEYS */; -/*!40000 ALTER TABLE `order` ENABLE KEYS */; -UNLOCK TABLES; - -- -- Table structure for table `order_product` -- @@ -187,15 +149,6 @@ CREATE TABLE `order_product` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Dumping data for table `order_product` --- - -LOCK TABLES `order_product` WRITE; -/*!40000 ALTER TABLE `order_product` DISABLE KEYS */; -/*!40000 ALTER TABLE `order_product` ENABLE KEYS */; -UNLOCK TABLES; - -- -- Table structure for table `password_change_request` -- @@ -215,15 +168,6 @@ CREATE TABLE `password_change_request` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Dumping data for table `password_change_request` --- - -LOCK TABLES `password_change_request` WRITE; -/*!40000 ALTER TABLE `password_change_request` DISABLE KEYS */; -/*!40000 ALTER TABLE `password_change_request` ENABLE KEYS */; -UNLOCK TABLES; - -- -- Table structure for table `product` -- @@ -249,16 +193,6 @@ CREATE TABLE `product` ( ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Dumping data for table `product` --- - -LOCK TABLES `product` WRITE; -/*!40000 ALTER TABLE `product` DISABLE KEYS */; -INSERT INTO `product` VALUES (1,'Espresso',5,'espresso.webp','Espresso in a white cup. Source: Dolce Gusto','Espresso',2.99,'A strong and concentrated coffee drink.','2024-04-28 12:37:10'),(2,'Cappuccino',120,'cappuccino.webp','Close-up of a steaming cup of freshly brewed Espresso with frothy milk on top. Source: Discount Coffee','Cappuccino',4.99,'An Italian coffee drink made with espresso, hot milk, and steamed milk foam.','2024-05-21 12:37:10'),(3,'Caffè Latte',190,'latte.avif','A latte with a spoon. Source: Peet\'s Coffee.','Latte',3.99,'A coffee drink made with espresso and steamed milk.','2024-04-23 12:37:10'),(4,'Caffè Americano',15,'americano.webp','Close-up of a clear glass mug filled with hot, black Americano coffee, topped with a thin layer of creme. Source: Peet\'s Coffee.','Americano',3.49,'A coffee drink prepared by diluting espresso with hot water.','2024-01-21 12:37:10'),(5,'Caffè Mocha',370,'mocha.png','Rich and indulgent mocha served in a ceramic mug, topped with whipped cream and a dusting of cocoa powder. Source: Starbucks','Mocha',4.49,'A chocolate-flavored variant of a latte, often with whipped cream on top.','2024-04-21 12:37:10'),(6,'White Chocolate Mocha',390,'white-chocolate-mocha.png','Rich and indulgent mocha served in a ceramic mug, topped with whipped cream and a dusting of cocoa powder. Source: Starbucks','Mocha',5.69,'Our signature mocha meets white chocolate sauce and steamed milk, and then is finished off with sweetened whipped cream to create this supreme white chocolate delight.','2024-04-25 10:33:02'),(7,'Cinnamon Dolce Latte\n',340,'cinnamon-dolce-latte.webp','Steamed milk and cinnamon dolce-flavored syrup on Latte. Source: Starbucks ','Latte',7.88,'We add freshly steamed milk and cinnamon dolce-flavored syrup to our classic espresso, topped with sweetened whipped cream and a cinnamon dolce topping to bring you specialness in a treat.','2024-04-25 10:37:23'),(8,'Caramel Macchiato',250,'caramel-macchiato.png','Freshly steamed milk with vanilla-flavored syrup marked with espresso and topped with a caramel drizzle for an oh-so-sweet finish. Source: Starbucks','Macchiato',3.33,'Freshly steamed milk with vanilla-flavored syrup marked with espresso and topped with a caramel drizzle for an oh-so-sweet finish.','2024-04-25 10:45:50'),(9,'Espresso Macchiato',15,'espresso-macchiato.png','Our rich espresso marked with dollop of steamed milk and foam. A European-style classic. Source: Starbucks','Macchiato',8.85,'Our rich espresso marked with dollop of steamed milk and foam. A European-style classic.','2024-04-25 10:48:35'),(10,'Espresso Con Panna',35,'espresso-con-panna.webp','Espresso meets a dollop of whipped cream to enhance the rich and caramelly flavors of a straight-up shot. Source: Starbucks','Espresso',4.34,'Espresso meets a dollop of whipped cream to enhance the rich and caramelly flavors of a straight-up shot.','2024-04-25 10:52:07'); -/*!40000 ALTER TABLE `product` ENABLE KEYS */; -UNLOCK TABLES; - -- -- Table structure for table `review` -- @@ -283,15 +217,6 @@ CREATE TABLE `review` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Dumping data for table `review` --- - -LOCK TABLES `review` WRITE; -/*!40000 ALTER TABLE `review` DISABLE KEYS */; -/*!40000 ALTER TABLE `review` ENABLE KEYS */; -UNLOCK TABLES; - -- -- Table structure for table `store` -- @@ -310,19 +235,9 @@ CREATE TABLE `store` ( KEY `store_district_district_id_fk` (`district_id`), SPATIAL KEY `store_coordinate_index` (`coordinate`), CONSTRAINT `store_district_district_id_fk` FOREIGN KEY (`district_id`) REFERENCES `district` (`district_id`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Dumping data for table `store` --- - -LOCK TABLES `store` WRITE; -/*!40000 ALTER TABLE `store` DISABLE KEYS */; -INSERT INTO `store` VALUES (1,'+230 630 1329','Royal Road','\0\0\0\0\0\0\0��&†74�J{�/L�L@',1,'Bagatelle'),(2,'+230 630 1234','Angus Road','\0\0\0\0\0\0\0��&†74����&�U@',4,'Albion'); -/*!40000 ALTER TABLE `store` ENABLE KEYS */; -UNLOCK TABLES; - -- -- Table structure for table `store_product` -- @@ -341,16 +256,6 @@ CREATE TABLE `store_product` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Dumping data for table `store_product` --- - -LOCK TABLES `store_product` WRITE; -/*!40000 ALTER TABLE `store_product` DISABLE KEYS */; -INSERT INTO `store_product` VALUES (1,1,5),(1,2,100),(1,3,56),(1,4,4),(1,5,2),(2,1,22),(2,3,13),(2,4,12); -/*!40000 ALTER TABLE `store_product` ENABLE KEYS */; -UNLOCK TABLES; - -- -- Table structure for table `user` -- @@ -374,15 +279,6 @@ CREATE TABLE `user` ( CONSTRAINT `last_name_length` CHECK (char_length(`first_name`) > 2) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `user` --- - -LOCK TABLES `user` WRITE; -/*!40000 ALTER TABLE `user` DISABLE KEYS */; -/*!40000 ALTER TABLE `user` ENABLE KEYS */; -UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; @@ -393,4 +289,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2024-05-15 19:34:31 +-- Dump completed on 2024-05-15 20:45:06 From c381b0de74d10e5aa129e848538f00349b2ceb48 Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Wed, 15 May 2024 21:14:57 +0400 Subject: [PATCH 02/13] create a separate script for creating testing database --- resources/database/cafe_test_schema.sql | 292 ++++++++++++++++++++++++ 1 file changed, 292 insertions(+) create mode 100644 resources/database/cafe_test_schema.sql diff --git a/resources/database/cafe_test_schema.sql b/resources/database/cafe_test_schema.sql new file mode 100644 index 0000000..2787a5f --- /dev/null +++ b/resources/database/cafe_test_schema.sql @@ -0,0 +1,292 @@ +-- MySQL dump 10.19 Distrib 10.3.38-MariaDB, for debian-linux-gnu (x86_64) +-- +-- Host: localhost Database: cafe_test +-- ------------------------------------------------------ +-- Server version 10.3.38-MariaDB-0ubuntu0.20.04.1 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Current Database: `cafe_test` +-- + +CREATE DATABASE /*!32312 IF NOT EXISTS*/ `cafe_test` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci */; + +USE `cafe_test`; + +-- +-- Table structure for table `administrator` +-- + +DROP TABLE IF EXISTS `administrator`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `administrator` ( + `user_id` int(11) unsigned NOT NULL, + `job_title` varchar(255) NOT NULL, + `is_super_admin` tinyint(1) DEFAULT 0, + PRIMARY KEY (`user_id`), + CONSTRAINT `admin_fk` FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `job_title_length` CHECK (char_length(`job_title`) > 3) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `client` +-- + +DROP TABLE IF EXISTS `client`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `client` ( + `user_id` int(11) unsigned NOT NULL, + `street` varchar(255) NOT NULL, + `city` varchar(255) NOT NULL, + `district_id` int(11) unsigned DEFAULT NULL, + PRIMARY KEY (`user_id`), + KEY `client_district_district_id_fk` (`district_id`), + CONSTRAINT `client_district_district_id_fk` FOREIGN KEY (`district_id`) REFERENCES `district` (`district_id`) ON UPDATE CASCADE, + CONSTRAINT `client_fk` FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `client_city_length` CHECK (char_length(`city`) > 2), + CONSTRAINT `client_street_length` CHECK (char_length(`street`) > 3) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `comment` +-- + +DROP TABLE IF EXISTS `comment`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `comment` ( + `comment_id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `text` varchar(2000) NOT NULL, + `created_date` datetime NOT NULL DEFAULT current_timestamp(), + `parent_comment_id` int(10) unsigned DEFAULT NULL, + `user_id` int(10) unsigned NOT NULL, + `review_id` int(10) unsigned DEFAULT NULL, + PRIMARY KEY (`comment_id`), + KEY `comment_comment_comment_id_fk` (`parent_comment_id`), + KEY `comment_user_user_id_fk` (`user_id`), + KEY `comment_review_review_id_fk` (`review_id`), + CONSTRAINT `comment_comment_comment_id_fk` FOREIGN KEY (`parent_comment_id`) REFERENCES `comment` (`comment_id`), + CONSTRAINT `comment_review_review_id_fk` FOREIGN KEY (`review_id`) REFERENCES `review` (`review_id`), + CONSTRAINT `comment_user_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `district` +-- + +DROP TABLE IF EXISTS `district`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `district` ( + `district_id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(30) NOT NULL, + PRIMARY KEY (`district_id`), + UNIQUE KEY `name` (`name`), + CONSTRAINT `name_values` CHECK (`name` in ('Moka','Port Louis','Flacq','Curepipe','Black River','Savanne','Grand Port','Riviere du Rempart','Pamplemousses','Mahebourg','Plaines Wilhems')) +) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `order` +-- + +DROP TABLE IF EXISTS `order`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `order` ( + `order_id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `status` varchar(20) DEFAULT 'pending', + `created_date` datetime DEFAULT current_timestamp(), + `pickup_date` datetime DEFAULT NULL, + `client_id` int(11) unsigned DEFAULT NULL, + `store_id` int(10) unsigned DEFAULT NULL, + PRIMARY KEY (`order_id`), + KEY `order_fk` (`client_id`), + KEY `order_store_store_id_fk` (`store_id`), + CONSTRAINT `order_fk` FOREIGN KEY (`client_id`) REFERENCES `client` (`user_id`) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `order_store_store_id_fk` FOREIGN KEY (`store_id`) REFERENCES `store` (`store_id`), + CONSTRAINT `pickup_date_range` CHECK (`pickup_date` is null or `pickup_date` >= `created_date`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `order_product` +-- + +DROP TABLE IF EXISTS `order_product`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `order_product` ( + `order_id` int(11) unsigned NOT NULL, + `product_id` int(11) unsigned NOT NULL, + `cup_size` varchar(20) NOT NULL, + `milk_type` varchar(20) NOT NULL, + `quantity` int(11) unsigned DEFAULT NULL, + `unit_price` decimal(10,2) DEFAULT NULL, + PRIMARY KEY (`order_id`,`product_id`,`cup_size`,`milk_type`), + KEY `order_product_product_product_id_fk` (`product_id`), + CONSTRAINT `order_product_order_order_id_fk` FOREIGN KEY (`order_id`) REFERENCES `order` (`order_id`), + CONSTRAINT `order_product_product_product_id_fk` FOREIGN KEY (`product_id`) REFERENCES `product` (`product_id`), + CONSTRAINT `cup_size` CHECK (`cup_size` in ('small','medium','large')), + CONSTRAINT `milk_type` CHECK (`milk_type` in ('almond','coconut','oat','soy')), + CONSTRAINT `quantity_range` CHECK (`quantity` > 0), + CONSTRAINT `unit_price_range` CHECK (`unit_price` > 0) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `password_change_request` +-- + +DROP TABLE IF EXISTS `password_change_request`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `password_change_request` ( + `request_id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `user_id` int(11) unsigned NOT NULL, + `token_hash` varchar(255) NOT NULL, + `expiry_date` datetime NOT NULL, + `used` tinyint(1) NOT NULL DEFAULT 0, + PRIMARY KEY (`request_id`), + KEY `request_fk` (`user_id`), + CONSTRAINT `request_fk` FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `product` +-- + +DROP TABLE IF EXISTS `product`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `product` ( + `product_id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + `calories` int(11) unsigned DEFAULT NULL CHECK (`calories` >= 0), + `img_url` varchar(255) NOT NULL, + `img_alt_text` varchar(150) NOT NULL, + `category` varchar(50) NOT NULL, + `price` decimal(10,2) NOT NULL, + `description` text DEFAULT NULL CHECK (char_length(`description`) > 0), + `created_date` datetime NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`product_id`), + CONSTRAINT `name_length` CHECK (char_length(`name`) > 2), + CONSTRAINT `img_alt_text_length` CHECK (char_length(`img_alt_text`) between 5 and 150), + CONSTRAINT `category_length` CHECK (char_length(`category`) > 2), + CONSTRAINT `img_url_format` CHECK (`img_url` like '%.png' or `img_url` like '%.jpeg' or `img_url` like '%.avif' or `img_url` like '%.jpg' or `img_url` like '%.webp') +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `review` +-- + +DROP TABLE IF EXISTS `review`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `review` ( + `review_id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `rating` int(11) unsigned NOT NULL, + `created_date` datetime NOT NULL DEFAULT current_timestamp(), + `text` varchar(2000) NOT NULL, + `client_id` int(11) unsigned DEFAULT NULL, + `product_id` int(11) unsigned DEFAULT NULL, + PRIMARY KEY (`review_id`), + KEY `review_1fk` (`client_id`), + KEY `review_2fk` (`product_id`), + CONSTRAINT `review_1fk` FOREIGN KEY (`client_id`) REFERENCES `client` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `review_2fk` FOREIGN KEY (`product_id`) REFERENCES `product` (`product_id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `check_rating` CHECK (`rating` between 1 and 5), + CONSTRAINT `text_length` CHECK (char_length(`text`) >= 2) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `store` +-- + +DROP TABLE IF EXISTS `store`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `store` ( + `store_id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `phone_no` varchar(255) NOT NULL, + `street` varchar(255) NOT NULL, + `coordinate` point NOT NULL, + `district_id` int(10) unsigned NOT NULL, + `city` varchar(255) NOT NULL, + PRIMARY KEY (`store_id`), + KEY `store_district_district_id_fk` (`district_id`), + SPATIAL KEY `store_coordinate_index` (`coordinate`), + CONSTRAINT `store_district_district_id_fk` FOREIGN KEY (`district_id`) REFERENCES `district` (`district_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `store_product` +-- + +DROP TABLE IF EXISTS `store_product`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `store_product` ( + `store_id` int(11) unsigned NOT NULL, + `product_id` int(11) unsigned NOT NULL, + `stock_level` int(10) unsigned NOT NULL DEFAULT 0, + PRIMARY KEY (`store_id`,`product_id`), + KEY `store_product_product_product_id_fk` (`product_id`), + CONSTRAINT `store_product_product_product_id_fk` FOREIGN KEY (`product_id`) REFERENCES `product` (`product_id`), + CONSTRAINT `store_product_store_store_id_fk` FOREIGN KEY (`store_id`) REFERENCES `store` (`store_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `user` +-- + +DROP TABLE IF EXISTS `user`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `user` ( + `user_id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `email` varchar(320) NOT NULL, + `first_name` varchar(255) DEFAULT NULL, + `password` varchar(255) DEFAULT NULL, + `phone_no` varchar(255) NOT NULL, + `last_name` varchar(255) DEFAULT NULL, + PRIMARY KEY (`user_id`), + UNIQUE KEY `unique_email` (`email`), + CONSTRAINT `email_format` CHECK (`email` like '%@%.%'), + CONSTRAINT `password_length` CHECK (char_length(`password`) > 8), + CONSTRAINT `phone_number_length` CHECK (char_length(`phone_no`) > 6), + CONSTRAINT `first_name_length` CHECK (char_length(`first_name`) > 2), + CONSTRAINT `last_name_length` CHECK (char_length(`first_name`) > 2) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2024-05-15 20:45:06 From 313b6035ac22752aa082af30259e5d4e3366611e Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Wed, 15 May 2024 21:18:42 +0400 Subject: [PATCH 03/13] use `cafe_test_schema` to setup the testing database --- .github/workflows/test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3677074..424e26a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,8 +34,7 @@ jobs: run: | mysql -V sudo /etc/init.d/mysql start - mysql -e "CREATE DATABASE IF NOT EXISTS $TEST_DB_NAME;" -u$DB_USER -p$DB_PASSWORD - mysql -D$TEST_DB_NAME -u$DB_USER -p$DB_PASSWORD -hlocalhost -P3306 < "resources/database/dump/cafe.sql" + mysql -D$TEST_DB_NAME -u$DB_USER -p$DB_PASSWORD -hlocalhost -P3306 < "resources/database/cafe_test_schema.sql" mysql -e "USE cafe_test; SHOW TABLES;" -u$DB_USER -p$DB_PASSWORD - name: Create .env file From 42627c761a3d99247712de9d8e44b67483d3ae61 Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Wed, 15 May 2024 21:30:07 +0400 Subject: [PATCH 04/13] update commands for exporting database --- docs/USAGE_GUIDE.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/USAGE_GUIDE.md b/docs/USAGE_GUIDE.md index 5a635c0..87a332a 100644 --- a/docs/USAGE_GUIDE.md +++ b/docs/USAGE_GUIDE.md @@ -34,10 +34,16 @@ Assuming that your MySQL database is running, in the root directory of the proje composer test ``` -## Backup database +## Export database -To export database with `mysqldump`: +To export only the schema of the `cafe` database: ```bash -mysqldump -u root -p cafe > resources/database/dump/cafe.sql +mysqldump -u root -p --no-data --databases cafe > resources/database/cafe_schema.sql +``` + +To export only the data in the `cafe` database: + +```bash +mysqldump -u root -p --no-create-info cafe > resources/database/data.sql ``` \ No newline at end of file From e32f9f295f133685b9408feabf4425006555b261 Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Wed, 15 May 2024 21:30:46 +0400 Subject: [PATCH 05/13] update commands for setting up database --- docs/INSTALLATION_GUIDE.md | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/docs/INSTALLATION_GUIDE.md b/docs/INSTALLATION_GUIDE.md index af68b7c..9de3526 100644 --- a/docs/INSTALLATION_GUIDE.md +++ b/docs/INSTALLATION_GUIDE.md @@ -80,36 +80,29 @@ whenever a client places an order. ## Database setup -Start your MySQL server and connect to its monitor: +Start your MySQL server: ```bash sudo service mysql start -mysql -u -p ``` -> [!NOTE] -> `` is a placeholder for your MySQL username. If your username is `root`, the command to run -> becomes `mysql -u root -p` - -Create a database `cafe`: +Create production database `cafe`: -```sql -create database cafe; -use cafe; -source resources/database/dump/cafe.sql; -exit; +```bash +mysql -u root -p < resources/database/cafe_schema.sql ``` -The path to the SQL dump must be modified your present working directory is not the root directory of the project. +Import data to production database: -If you want to run tests with composer, you must first set up a separate database for testing. To do so, repeat the -same instructions as above except name the testing database `cafe_test`: +```bash +mysql -u root -p cafe < resources/database/data.sql +``` + +If you want to run tests with composer, you must first set up a separate database `cafe_test` for testing. +To create the testing database `cafe_test`: -```sql -create database cafe_test; -use cafe_test; -source resources/database/dump/cafe.sql; -exit; +```bash +mysql -u root -p < resources/database/cafe_test_schema.sql ``` ## Virtual host setup From f6409f3e7036ba9b389d0953a24a2543978871cd Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Thu, 16 May 2024 10:52:17 +0400 Subject: [PATCH 06/13] autoincrement should start from 1 for all tables --- resources/database/cafe_schema.sql | 4 ++-- resources/database/cafe_test_schema.sql | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/database/cafe_schema.sql b/resources/database/cafe_schema.sql index 3229df5..e23c94e 100644 --- a/resources/database/cafe_schema.sql +++ b/resources/database/cafe_schema.sql @@ -98,7 +98,7 @@ CREATE TABLE `district` ( PRIMARY KEY (`district_id`), UNIQUE KEY `name` (`name`), CONSTRAINT `name_values` CHECK (`name` in ('Moka','Port Louis','Flacq','Curepipe','Black River','Savanne','Grand Port','Riviere du Rempart','Pamplemousses','Mahebourg','Plaines Wilhems')) -) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -190,7 +190,7 @@ CREATE TABLE `product` ( CONSTRAINT `img_alt_text_length` CHECK (char_length(`img_alt_text`) between 5 and 150), CONSTRAINT `category_length` CHECK (char_length(`category`) > 2), CONSTRAINT `img_url_format` CHECK (`img_url` like '%.png' or `img_url` like '%.jpeg' or `img_url` like '%.avif' or `img_url` like '%.jpg' or `img_url` like '%.webp') -) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- diff --git a/resources/database/cafe_test_schema.sql b/resources/database/cafe_test_schema.sql index 2787a5f..106b02d 100644 --- a/resources/database/cafe_test_schema.sql +++ b/resources/database/cafe_test_schema.sql @@ -98,7 +98,7 @@ CREATE TABLE `district` ( PRIMARY KEY (`district_id`), UNIQUE KEY `name` (`name`), CONSTRAINT `name_values` CHECK (`name` in ('Moka','Port Louis','Flacq','Curepipe','Black River','Savanne','Grand Port','Riviere du Rempart','Pamplemousses','Mahebourg','Plaines Wilhems')) -) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -190,7 +190,7 @@ CREATE TABLE `product` ( CONSTRAINT `img_alt_text_length` CHECK (char_length(`img_alt_text`) between 5 and 150), CONSTRAINT `category_length` CHECK (char_length(`category`) > 2), CONSTRAINT `img_url_format` CHECK (`img_url` like '%.png' or `img_url` like '%.jpeg' or `img_url` like '%.avif' or `img_url` like '%.jpg' or `img_url` like '%.webp') -) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- From c3d15754c9a287eedc563786c0b404e6de4a1c52 Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Thu, 16 May 2024 10:58:33 +0400 Subject: [PATCH 07/13] add data dump --- resources/database/data.sql | 143 ++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 resources/database/data.sql diff --git a/resources/database/data.sql b/resources/database/data.sql new file mode 100644 index 0000000..6ad8cf8 --- /dev/null +++ b/resources/database/data.sql @@ -0,0 +1,143 @@ +-- MySQL dump 10.19 Distrib 10.3.38-MariaDB, for debian-linux-gnu (x86_64) +-- +-- Host: localhost Database: cafe +-- ------------------------------------------------------ +-- Server version 10.3.38-MariaDB-0ubuntu0.20.04.1 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Dumping data for table `administrator` +-- + +LOCK TABLES `administrator` WRITE; +/*!40000 ALTER TABLE `administrator` DISABLE KEYS */; +/*!40000 ALTER TABLE `administrator` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Dumping data for table `client` +-- + +LOCK TABLES `client` WRITE; +/*!40000 ALTER TABLE `client` DISABLE KEYS */; +INSERT INTO `client` VALUES (1,'Royal Road','Rochester',2),(10,'Main Road','Curepipe',9); +/*!40000 ALTER TABLE `client` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Dumping data for table `comment` +-- + +LOCK TABLES `comment` WRITE; +/*!40000 ALTER TABLE `comment` DISABLE KEYS */; +INSERT INTO `comment` VALUES (33,'this is a comment','2024-05-16 10:41:34',NULL,10,20),(34,'this is another comment','2024-05-16 10:41:43',33,10,20),(35,'ok','2024-05-16 10:42:11',NULL,10,23),(36,'i am replying to your comment\r\n\r\ni can write multiple paragraphs.\r\n\r\nthis is so cool.','2024-05-16 10:46:54',33,1,20),(37,'i can comment on my own review','2024-05-16 10:47:27',NULL,1,23); +/*!40000 ALTER TABLE `comment` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Dumping data for table `district` +-- + +LOCK TABLES `district` WRITE; +/*!40000 ALTER TABLE `district` DISABLE KEYS */; +INSERT INTO `district` VALUES (4,'Black River'),(3,'Flacq'),(6,'Grand Port'),(1,'Moka'),(8,'Pamplemousses'),(9,'Plaines Wilhems'),(2,'Port Louis'),(7,'Riviere du Rempart'),(5,'Savanne'); +/*!40000 ALTER TABLE `district` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Dumping data for table `order` +-- + +LOCK TABLES `order` WRITE; +/*!40000 ALTER TABLE `order` DISABLE KEYS */; +INSERT INTO `order` VALUES (1,'pending','2024-05-16 10:33:54',NULL,1,1); +/*!40000 ALTER TABLE `order` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Dumping data for table `order_product` +-- + +LOCK TABLES `order_product` WRITE; +/*!40000 ALTER TABLE `order_product` DISABLE KEYS */; +INSERT INTO `order_product` VALUES (1,1,'medium','oat',1,2.99),(1,2,'small','almond',1,4.99); +/*!40000 ALTER TABLE `order_product` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Dumping data for table `password_change_request` +-- + +LOCK TABLES `password_change_request` WRITE; +/*!40000 ALTER TABLE `password_change_request` DISABLE KEYS */; +/*!40000 ALTER TABLE `password_change_request` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Dumping data for table `product` +-- + +LOCK TABLES `product` WRITE; +/*!40000 ALTER TABLE `product` DISABLE KEYS */; +INSERT INTO `product` VALUES (1,'Espresso',5,'espresso.webp','Espresso in a white cup. Source: Dolce Gusto','Espresso',2.99,'A strong and concentrated coffee drink.','2024-04-28 12:37:10'),(2,'Cappuccino',120,'cappuccino.webp','Close-up of a steaming cup of freshly brewed Espresso with frothy milk on top. Source: Discount Coffee','Cappuccino',4.99,'An Italian coffee drink made with espresso, hot milk, and steamed milk foam.','2024-05-21 12:37:10'),(3,'Caffè Latte',190,'latte.avif','A latte with a spoon. Source: Peet\'s Coffee.','Latte',3.99,'A coffee drink made with espresso and steamed milk.','2024-04-23 12:37:10'),(4,'Caffè Americano',15,'americano.webp','Close-up of a clear glass mug filled with hot, black Americano coffee, topped with a thin layer of creme. Source: Peet\'s Coffee.','Americano',3.49,'A coffee drink prepared by diluting espresso with hot water.','2024-01-21 12:37:10'),(5,'Caffè Mocha',370,'mocha.png','Rich and indulgent mocha served in a ceramic mug, topped with whipped cream and a dusting of cocoa powder. Source: Starbucks','Mocha',4.49,'A chocolate-flavored variant of a latte, often with whipped cream on top.','2024-04-21 12:37:10'),(6,'White Chocolate Mocha',390,'white-chocolate-mocha.png','Rich and indulgent mocha served in a ceramic mug, topped with whipped cream and a dusting of cocoa powder. Source: Starbucks','Mocha',5.69,'Our signature mocha meets white chocolate sauce and steamed milk, and then is finished off with sweetened whipped cream to create this supreme white chocolate delight.','2024-04-25 10:33:02'),(7,'Cinnamon Dolce Latte\n',340,'cinnamon-dolce-latte.webp','Steamed milk and cinnamon dolce-flavored syrup on Latte. Source: Starbucks ','Latte',7.88,'We add freshly steamed milk and cinnamon dolce-flavored syrup to our classic espresso, topped with sweetened whipped cream and a cinnamon dolce topping to bring you specialness in a treat.','2024-04-25 10:37:23'),(8,'Caramel Macchiato',250,'caramel-macchiato.png','Freshly steamed milk with vanilla-flavored syrup marked with espresso and topped with a caramel drizzle for an oh-so-sweet finish. Source: Starbucks','Macchiato',3.33,'Freshly steamed milk with vanilla-flavored syrup marked with espresso and topped with a caramel drizzle for an oh-so-sweet finish.','2024-04-25 10:45:50'),(9,'Espresso Macchiato',15,'espresso-macchiato.png','Our rich espresso marked with dollop of steamed milk and foam. A European-style classic. Source: Starbucks','Macchiato',8.85,'Our rich espresso marked with dollop of steamed milk and foam. A European-style classic.','2024-04-25 10:48:35'),(10,'Espresso Con Panna',35,'espresso-con-panna.webp','Espresso meets a dollop of whipped cream to enhance the rich and caramelly flavors of a straight-up shot. Source: Starbucks','Espresso',4.34,'Espresso meets a dollop of whipped cream to enhance the rich and caramelly flavors of a straight-up shot.','2024-04-25 10:52:07'); +/*!40000 ALTER TABLE `product` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Dumping data for table `review` +-- + +LOCK TABLES `review` WRITE; +/*!40000 ALTER TABLE `review` DISABLE KEYS */; +INSERT INTO `review` VALUES (20,5,'2024-05-16 10:32:22','i really like the taste. I have previously bought this product so I have a verified badge.',1,1),(21,3,'2024-05-16 10:35:20','I have never bought this product before.',1,8),(22,1,'2024-05-16 10:35:57','this is another fake review',1,8),(23,3,'2024-05-16 10:37:16','reviews can contain emojis 💯💯',1,1),(24,1,'2024-05-16 10:43:26','this is a negative review',10,1),(25,4,'2024-05-16 10:44:01','i like coffee',10,2),(26,1,'2024-05-16 10:44:18','the latte was bad',10,3),(27,3,'2024-05-16 10:44:57','the cup was too hot',10,4),(28,3,'2024-05-16 10:48:51','Ratings from people who have not bought the product are not taken into account when calculating the average rating of a product',1,3); +/*!40000 ALTER TABLE `review` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Dumping data for table `store` +-- + +LOCK TABLES `store` WRITE; +/*!40000 ALTER TABLE `store` DISABLE KEYS */; +INSERT INTO `store` VALUES (1,'+230 630 1329','Royal Road','\0\0\0\0\0\0\0��&†74�J{�/L�L@',1,'Bagatelle'),(2,'+230 630 1234','Angus Road','\0\0\0\0\0\0\0��&†74����&�U@',4,'Albion'); +/*!40000 ALTER TABLE `store` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Dumping data for table `store_product` +-- + +LOCK TABLES `store_product` WRITE; +/*!40000 ALTER TABLE `store_product` DISABLE KEYS */; +INSERT INTO `store_product` VALUES (1,1,3),(1,2,5439),(1,3,54),(1,4,38),(1,5,998),(2,1,22),(2,3,13),(2,4,12); +/*!40000 ALTER TABLE `store_product` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Dumping data for table `user` +-- + +LOCK TABLES `user` WRITE; +/*!40000 ALTER TABLE `user` DISABLE KEYS */; +INSERT INTO `user` VALUES (1,'c34560814@gmail.com','john','$2y$10$Gz37vrrGkoaOSoGKvJWgRegKWExfRAKs8UjxUdyyyrRwD6Q43sfZW','+230-5-123-4567','💋💋💋'),(2,'divjok28@outlook.com','Divyesh','$2y$10$T3MJs2am7g1QKeGDrHZ4VuEKRmTk.vYTPZBC6nKULl3lAzf/KpM1G','+230-5-123-4567','Jokhoo'); +/*!40000 ALTER TABLE `user` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2024-05-16 10:53:12 From 698e04f569298b211b1236008488cbdb936628a1 Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Thu, 16 May 2024 11:17:27 +0400 Subject: [PATCH 08/13] make comments and review start at ID 1 --- resources/database/data.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/database/data.sql b/resources/database/data.sql index 6ad8cf8..4c98c11 100644 --- a/resources/database/data.sql +++ b/resources/database/data.sql @@ -39,7 +39,7 @@ UNLOCK TABLES; LOCK TABLES `comment` WRITE; /*!40000 ALTER TABLE `comment` DISABLE KEYS */; -INSERT INTO `comment` VALUES (33,'this is a comment','2024-05-16 10:41:34',NULL,10,20),(34,'this is another comment','2024-05-16 10:41:43',33,10,20),(35,'ok','2024-05-16 10:42:11',NULL,10,23),(36,'i am replying to your comment\r\n\r\ni can write multiple paragraphs.\r\n\r\nthis is so cool.','2024-05-16 10:46:54',33,1,20),(37,'i can comment on my own review','2024-05-16 10:47:27',NULL,1,23); +INSERT INTO `comment` VALUES (1,'i can comment on my own review','2024-05-16 11:12:19',NULL,1,3); /*!40000 ALTER TABLE `comment` ENABLE KEYS */; UNLOCK TABLES; @@ -98,7 +98,7 @@ UNLOCK TABLES; LOCK TABLES `review` WRITE; /*!40000 ALTER TABLE `review` DISABLE KEYS */; -INSERT INTO `review` VALUES (20,5,'2024-05-16 10:32:22','i really like the taste. I have previously bought this product so I have a verified badge.',1,1),(21,3,'2024-05-16 10:35:20','I have never bought this product before.',1,8),(22,1,'2024-05-16 10:35:57','this is another fake review',1,8),(23,3,'2024-05-16 10:37:16','reviews can contain emojis 💯💯',1,1),(24,1,'2024-05-16 10:43:26','this is a negative review',10,1),(25,4,'2024-05-16 10:44:01','i like coffee',10,2),(26,1,'2024-05-16 10:44:18','the latte was bad',10,3),(27,3,'2024-05-16 10:44:57','the cup was too hot',10,4),(28,3,'2024-05-16 10:48:51','Ratings from people who have not bought the product are not taken into account when calculating the average rating of a product',1,3); +INSERT INTO `review` VALUES (1,5,'2024-05-16 11:11:02','i really like this product. I have a verified badge since I have actually bought this product.',1,1),(2,3,'2024-05-16 11:11:24','the coffee is decent but nothing special',1,2),(3,2,'2024-05-16 11:11:53','i would love to buy this again but the price is not worth it',1,3),(4,1,'2024-05-16 11:14:04','Note the calculation for average rating does not consider unverified reviews',1,3); /*!40000 ALTER TABLE `review` ENABLE KEYS */; UNLOCK TABLES; @@ -140,4 +140,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2024-05-16 10:53:12 +-- Dump completed on 2024-05-16 11:16:58 From a35ae703f574bd636f8bf2337704911258695aa7 Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Thu, 16 May 2024 11:24:09 +0400 Subject: [PATCH 09/13] add more comments and reviews, update divyesh account --- resources/database/data.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/resources/database/data.sql b/resources/database/data.sql index 4c98c11..0d066e4 100644 --- a/resources/database/data.sql +++ b/resources/database/data.sql @@ -29,7 +29,7 @@ UNLOCK TABLES; LOCK TABLES `client` WRITE; /*!40000 ALTER TABLE `client` DISABLE KEYS */; -INSERT INTO `client` VALUES (1,'Royal Road','Rochester',2),(10,'Main Road','Curepipe',9); +INSERT INTO `client` VALUES (1,'Royal Road','Rochester',2),(2,'Main Road','Curepipe',9),(10,'Main Road','Curepipe',9); /*!40000 ALTER TABLE `client` ENABLE KEYS */; UNLOCK TABLES; @@ -39,7 +39,7 @@ UNLOCK TABLES; LOCK TABLES `comment` WRITE; /*!40000 ALTER TABLE `comment` DISABLE KEYS */; -INSERT INTO `comment` VALUES (1,'i can comment on my own review','2024-05-16 11:12:19',NULL,1,3); +INSERT INTO `comment` VALUES (1,'i can comment on my own review','2024-05-16 11:12:19',NULL,1,3),(2,'i am commenting something here','2024-05-16 11:21:36',NULL,2,1),(3,'comments can be nested','2024-05-16 11:21:46',2,2,1),(4,'test','2024-05-16 11:22:02',NULL,2,5),(5,'ok','2024-05-16 11:22:10',NULL,2,2); /*!40000 ALTER TABLE `comment` ENABLE KEYS */; UNLOCK TABLES; @@ -98,7 +98,7 @@ UNLOCK TABLES; LOCK TABLES `review` WRITE; /*!40000 ALTER TABLE `review` DISABLE KEYS */; -INSERT INTO `review` VALUES (1,5,'2024-05-16 11:11:02','i really like this product. I have a verified badge since I have actually bought this product.',1,1),(2,3,'2024-05-16 11:11:24','the coffee is decent but nothing special',1,2),(3,2,'2024-05-16 11:11:53','i would love to buy this again but the price is not worth it',1,3),(4,1,'2024-05-16 11:14:04','Note the calculation for average rating does not consider unverified reviews',1,3); +INSERT INTO `review` VALUES (1,5,'2024-05-16 11:11:02','i really like this product. I have a verified badge since I have actually bought this product.',1,1),(2,3,'2024-05-16 11:11:24','the coffee is decent but nothing special',1,2),(3,2,'2024-05-16 11:11:53','i would love to buy this again but the price is not worth it',1,3),(4,1,'2024-05-16 11:14:04','Note the calculation for average rating does not consider unverified reviews',1,3),(5,1,'2024-05-16 11:21:56','this is a negative review',2,1),(6,3,'2024-05-16 11:22:44','this is a wonderful product that changed my life',2,3); /*!40000 ALTER TABLE `review` ENABLE KEYS */; UNLOCK TABLES; @@ -128,7 +128,7 @@ UNLOCK TABLES; LOCK TABLES `user` WRITE; /*!40000 ALTER TABLE `user` DISABLE KEYS */; -INSERT INTO `user` VALUES (1,'c34560814@gmail.com','john','$2y$10$Gz37vrrGkoaOSoGKvJWgRegKWExfRAKs8UjxUdyyyrRwD6Q43sfZW','+230-5-123-4567','💋💋💋'),(2,'divjok28@outlook.com','Divyesh','$2y$10$T3MJs2am7g1QKeGDrHZ4VuEKRmTk.vYTPZBC6nKULl3lAzf/KpM1G','+230-5-123-4567','Jokhoo'); +INSERT INTO `user` VALUES (1,'c34560814@gmail.com','john','$2y$10$Gz37vrrGkoaOSoGKvJWgRegKWExfRAKs8UjxUdyyyrRwD6Q43sfZW','+230-5-123-4567','💋💋💋'),(2,'divjok28@outlook.com','Divyesh','$2y$10$6Bj0y0J2r9OoGjjYpTThQenCsR6RHQ14fNm4E.CPBmHDqJbKsuPju','+230-5-123-4567','Jokhoo'); /*!40000 ALTER TABLE `user` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; @@ -140,4 +140,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2024-05-16 11:16:58 +-- Dump completed on 2024-05-16 11:23:20 From 051fa451b54316f2e20d9664909b20af62352ea9 Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Thu, 16 May 2024 11:38:49 +0400 Subject: [PATCH 10/13] rename data.sql to cafe_data.sql --- docs/INSTALLATION_GUIDE.md | 2 +- docs/USAGE_GUIDE.md | 2 +- resources/database/{data.sql => cafe_data.sql} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename resources/database/{data.sql => cafe_data.sql} (100%) diff --git a/docs/INSTALLATION_GUIDE.md b/docs/INSTALLATION_GUIDE.md index 9de3526..360ce8a 100644 --- a/docs/INSTALLATION_GUIDE.md +++ b/docs/INSTALLATION_GUIDE.md @@ -95,7 +95,7 @@ mysql -u root -p < resources/database/cafe_schema.sql Import data to production database: ```bash -mysql -u root -p cafe < resources/database/data.sql +mysql -u root -p cafe < resources/database/cafe_data.sql ``` If you want to run tests with composer, you must first set up a separate database `cafe_test` for testing. diff --git a/docs/USAGE_GUIDE.md b/docs/USAGE_GUIDE.md index 87a332a..a0953dc 100644 --- a/docs/USAGE_GUIDE.md +++ b/docs/USAGE_GUIDE.md @@ -45,5 +45,5 @@ mysqldump -u root -p --no-data --databases cafe > resources/database/cafe_schema To export only the data in the `cafe` database: ```bash -mysqldump -u root -p --no-create-info cafe > resources/database/data.sql +mysqldump -u root -p --no-create-info cafe > resources/database/cafe_data.sql ``` \ No newline at end of file diff --git a/resources/database/data.sql b/resources/database/cafe_data.sql similarity index 100% rename from resources/database/data.sql rename to resources/database/cafe_data.sql From 240212f23be3881341d56440ce1c921193dde9b1 Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Thu, 16 May 2024 11:44:55 +0400 Subject: [PATCH 11/13] add data for cafe_test --- docs/INSTALLATION_GUIDE.md | 4 ++-- resources/database/cafe_test_data.sql | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 resources/database/cafe_test_data.sql diff --git a/docs/INSTALLATION_GUIDE.md b/docs/INSTALLATION_GUIDE.md index 360ce8a..062ea7f 100644 --- a/docs/INSTALLATION_GUIDE.md +++ b/docs/INSTALLATION_GUIDE.md @@ -98,11 +98,11 @@ Import data to production database: mysql -u root -p cafe < resources/database/cafe_data.sql ``` -If you want to run tests with composer, you must first set up a separate database `cafe_test` for testing. -To create the testing database `cafe_test`: +If you want to run tests with composer, you must first set up a separate database `cafe_test` for testing: ```bash mysql -u root -p < resources/database/cafe_test_schema.sql +mysql -u root -p cafe_test < resources/database/cafe_test_data.sql ``` ## Virtual host setup diff --git a/resources/database/cafe_test_data.sql b/resources/database/cafe_test_data.sql new file mode 100644 index 0000000..34a928f --- /dev/null +++ b/resources/database/cafe_test_data.sql @@ -0,0 +1,23 @@ +-- MySQL dump 10.19 Distrib 10.3.38-MariaDB, for debian-linux-gnu (x86_64) +-- +-- Host: localhost Database: cafe_test +-- ------------------------------------------------------ +-- Server version 10.3.38-MariaDB-0ubuntu0.20.04.1 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +LOCK TABLES `district` WRITE; +/*!40000 ALTER TABLE `district` DISABLE KEYS */; +INSERT INTO `district` VALUES (4,'Black River'),(3,'Flacq'),(6,'Grand Port'),(1,'Moka'),(8,'Pamplemousses'),(9,'Plaines Wilhems'),(2,'Port Louis'),(7,'Riviere du Rempart'),(5,'Savanne'); +/*!40000 ALTER TABLE `district` ENABLE KEYS */; +UNLOCK TABLES; + +-- Dump completed on 2024-05-16 11:23:20 From ba294b2c175f0fe36d30efb090bd7c90d782cd26 Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Thu, 16 May 2024 11:45:47 +0400 Subject: [PATCH 12/13] remove unused TEST_DB_NAME, import data to test database --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 424e26a..78b7bd7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,6 @@ jobs: runs-on: ubuntu-latest env: - TEST_DB_NAME: cafe_test DB_USER: root # do not change DB_PASSWORD: root # do not change @@ -34,7 +33,8 @@ jobs: run: | mysql -V sudo /etc/init.d/mysql start - mysql -D$TEST_DB_NAME -u$DB_USER -p$DB_PASSWORD -hlocalhost -P3306 < "resources/database/cafe_test_schema.sql" + mysql -u$DB_USER -p$DB_PASSWORD -hlocalhost -P3306 < "resources/database/cafe_test_schema.sql" + mysql -u root -p cafe_test < "resources/database/cafe_test_data.sql" mysql -e "USE cafe_test; SHOW TABLES;" -u$DB_USER -p$DB_PASSWORD - name: Create .env file From b7fd0544528ac42f785646bf58233c265e085243 Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Thu, 16 May 2024 11:51:27 +0400 Subject: [PATCH 13/13] pass password in command line when importing data --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 78b7bd7..ab30772 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,7 +34,7 @@ jobs: mysql -V sudo /etc/init.d/mysql start mysql -u$DB_USER -p$DB_PASSWORD -hlocalhost -P3306 < "resources/database/cafe_test_schema.sql" - mysql -u root -p cafe_test < "resources/database/cafe_test_data.sql" + mysql -u$DB_USER -p$DB_PASSWORD -hlocalhost -P3306 -Dcafe_test < "resources/database/cafe_test_data.sql" mysql -e "USE cafe_test; SHOW TABLES;" -u$DB_USER -p$DB_PASSWORD - name: Create .env file