-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecipe.sql
More file actions
209 lines (163 loc) · 8.3 KB
/
Recipe.sql
File metadata and controls
209 lines (163 loc) · 8.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
DROP TABLE recipe_categories_join;
DROP TABLE recipes;
/*
recipes is the child table of recipe_courses, recipe_cuisines, and recipe_difficulties
the app will not allow the deletion of recipe_courses, recipe_cuisines, recipe_difficulties, and recipe_categories
i plan to allow for editing and adding of cuisines, and categories
No edit or add of difficulties or courses
Future note: primary keys best to be unsigned bigint-- why waste half the points
RecipeId bigint unsigned NOT NULL AUTO_INCREMENT
to back-up/restore use command prompt not power shell
first open command promp in C:\Program Files\MySQL\MySQL Server 8.0\bin
then run the below commands
to back-up:
mysqldump -u root -p usefulwebapps > C:\MySQLBackup\usefulwebapps_2024_09_03.sql
to restore:
mysql -u root -p usefulwebapps < C:\MySQLBackup\usefulwebapps_2024_09_03.sql
to transer files to Digital Ocean server from local windows PC using ubuntu terminal
scp Documents/my_file.txt user@123.45.67.89:/home/user/uploads
to transfer publish files
open ubuntu terminal in publish root foler then run this
scp -r * user@hostIP:/var/www/thedotnetwizard.com/html
scp (secure copy) is part of openssh-server which was installed durning ubuntu server setup -- ip above is bogus
to run the app on Ubuntu
go to /var/www/thedotnetwizard.com/html and type ./UsefulWebApps
*/
CREATE TABLE `recipes` (
`RecipeId` bigint unsigned NOT NULL AUTO_INCREMENT,
`RecipeTitle` varchar(100) NOT NULL,
`RecipeDescription` varchar(200) DEFAULT NULL,
`CourseId` bigint unsigned DEFAULT NULL,
`CuisineId` bigint unsigned DEFAULT NULL,
`DifficultyId` bigint unsigned DEFAULT NULL,
`PrepTime` smallint unsigned NOT NULL,
`CookTime` smallint unsigned NOT NULL,
`Rating` tinyint unsigned NOT NULL,
`Servings` tinyint unsigned NOT NULL,
`Nutrition` varchar(2000) DEFAULT NULL,
`Ingredients` varchar(3000) NOT NULL,
`Instructions` varchar(3000) NOT NULL,
`Notes` varchar(2000) DEFAULT NULL,
`UserId` varchar(255) NOT NULL,
PRIMARY KEY (`RecipeId`),
KEY `CourseId` (`CourseId`),
KEY `CuisineId` (`CuisineId`),
KEY `DifficultyId` (`DifficultyId`),
FULLTEXT KEY `fulltext` (`RecipeTitle`,`Ingredients`),
CONSTRAINT `recipes_ibfk_1` FOREIGN KEY (`CourseId`) REFERENCES `recipe_courses` (`CourseId`) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT `recipes_ibfk_2` FOREIGN KEY (`CuisineId`) REFERENCES `recipe_cuisines` (`CuisineId`) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT `recipes_ibfk_3` FOREIGN KEY (`DifficultyId`) REFERENCES `recipe_difficulties` (`DifficultyId`) ON DELETE RESTRICT ON UPDATE CASCADE
);
ALTER TABLE recipes add fulltext index `fulltext`(RecipeTitle, Ingredients);
ALTER TABLE recipes ADD UserId varchar(255) NOT NULL;
ALTER TABLE recipes ADD UserName varchar(256) NOT NULL;
ALTER TABLE recipes ADD ImagePath varchar(500) DEFAULT NULL;
show create table recipes;
UPDATE recipes SET UserId = '19e5b54f-e998-4494-90a2-797cfcfc9fc3', UserName = 'BeefCakeTheMightyStandardUser' WHERE RecipeId = 1;
UPDATE recipes SET UserId = '19e5b54f-e998-4494-90a2-797cfcfc9fc3', UserName = 'BeefCakeTheMightyStandardUser' WHERE RecipeId = 2;
UPDATE recipes SET UserId = '19e5b54f-e998-4494-90a2-797cfcfc9fc3', UserName = 'BeefCakeTheMightyStandardUser' WHERE RecipeId = 3;
UPDATE recipes SET UserId = '19e5b54f-e998-4494-90a2-797cfcfc9fc3', UserName = 'BeefCakeTheMightyStandardUser' WHERE RecipeId = 4;
UPDATE recipes SET UserId = '19e5b54f-e998-4494-90a2-797cfcfc9fc3', UserName = 'BeefCakeTheMightyStandardUser' WHERE RecipeId = 15;
UPDATE recipes SET UserId = '19e5b54f-e998-4494-90a2-797cfcfc9fc3', UserName = 'BeefCakeTheMightyStandardUser' WHERE RecipeId = 16;
UPDATE recipes SET UserId = '19e5b54f-e998-4494-90a2-797cfcfc9fc3', UserName = 'BeefCakeTheMightyStandardUser' WHERE RecipeId = 17;
UPDATE recipes SET UserId = '818fd1e7-05ab-44f5-9276-68f20ec3c70d', UserName = 'BeefCakeTheMightyAdmin' WHERE RecipeId = 18;
UPDATE recipes SET UserId = '818fd1e7-05ab-44f5-9276-68f20ec3c70d', UserName = 'BeefCakeTheMightyAdmin' WHERE RecipeId = 19;
UPDATE recipes SET UserId = '818fd1e7-05ab-44f5-9276-68f20ec3c70d', UserName = 'BeefCakeTheMightyAdmin' WHERE RecipeId = 20;
UPDATE recipes SET UserId = '818fd1e7-05ab-44f5-9276-68f20ec3c70d', UserName = 'BeefCakeTheMightyAdmin' WHERE RecipeId = 21;
UPDATE recipes SET UserId = '818fd1e7-05ab-44f5-9276-68f20ec3c70d', UserName = 'BeefCakeTheMightyAdmin' WHERE RecipeId = 22;
/*
MANY TO MANY
One recipe can have many categories
One category can have many recipies
*/
DROP TABLE recipe_categories;
CREATE TABLE `recipe_categories` (
`CategoryId` bigint unsigned NOT NULL AUTO_INCREMENT,
`Category` varchar(50) NOT NULL,
PRIMARY KEY (`CategoryId`)
);
INSERT INTO recipe_categories (Category)
VALUES ("Beverages"),("Sides"),("Breakfast"),
("Lunch"),("Brunch"),("Dinner"),
("Breads"),("Appetizers"),("Main Dish"),
("Dessert"),("Soups"),("Stews & Chili"),
("Pasta, Sauces, & Noodles"),("Salad & Dressings"),("Grilling"),
("Smoked"),("Burgers"),("Sandwiches"),
("Pizza"),("Slow & Pressure Cooker"),("Skillet & Stir-Fries"),
("Oven Baked & Broiled"),("Beans, Grains, & Rice"),("Tofu"),("Casseroles"),
("Diet"),("Meatless & Vegan"),("Eggs"),
("Poultry"),("Chicken"),("Duck"),("Turkey"),
("Beef"),("Veal"),("Pork"),("Lamb"),("Sausages"),("Other Meat - wild game etc."),
("Fish and Seafood"),("Nuts and Seeds"),
("Fruit"),("Vegetables"),
("Brownies"),("Cookies & Biscuits"),("Cakes & Cupcakes"),
("Custards & Puddings"),("Pies, Tarts, Cobblers, & Crisp"),("Chocolates & Candie"),
("Pastries"),("Frozen");
DROP TABLE recipe_categories_join;
CREATE TABLE `recipe_categories_join` (
`RecipeId` bigint unsigned NOT NULL,
`CategoryId` bigint unsigned NOT NULL,
PRIMARY KEY (`RecipeId`,`CategoryId`),
KEY `CategoryId` (`CategoryId`),
CONSTRAINT `recipe_categories_join_ibfk_1` FOREIGN KEY (`RecipeId`) REFERENCES `recipes` (`RecipeId`),
CONSTRAINT `recipe_categories_join_ibfk_2` FOREIGN KEY (`CategoryId`) REFERENCES `recipe_categories` (`CategoryId`)
);
/*
ONE TO MANY -- once recipe can have only one course but one course can have many recipes
Parent tables to recipes
*/
DROP TABLE recipe_courses;
CREATE TABLE `recipe_courses` (
`CourseId` bigint unsigned NOT NULL AUTO_INCREMENT,
`Course` varchar(50) NOT NULL,
PRIMARY KEY (`CourseId`)
);
INSERT INTO recipe_courses (Course)
VALUES ("Hors D'Oeuvre"),("Amuse-Bouche"),("Soup"),("Appetizer"),("Salad"),("Palate Cleanser"),("Main Course"),("Dessert"),("Mignardise");
DROP TABLE recipe_cuisines;
CREATE TABLE `recipe_cuisines` (
`CuisineId` bigint unsigned NOT NULL AUTO_INCREMENT,
`Cuisine` varchar(50) NOT NULL,
PRIMARY KEY (`CuisineId`)
);
INSERT INTO recipe_cuisines (Cuisine)
VALUES ("Italian"),("Indian"),("Mexican"),
("Japanese"),("French"),("Chinese"),
("Middle Eastern"),("Thai"),("Greek"),
("Brazilian"),("Spanish"),("Vietnamese"),
("Korean"),("African"),("Caribbean"),("American"),("Russian");
INSERT INTO recipe_cuisines (cuisine) VALUES ("SOME OTHER VALUE");
DROP TABLE recipe_difficulties;
CREATE TABLE `recipe_difficulties` (
`DifficultyId` bigint unsigned NOT NULL AUTO_INCREMENT,
`Difficulty` varchar(25) NOT NULL,
PRIMARY KEY (`DifficultyId`)
);
INSERT INTO recipe_difficulties (Difficulty)
VALUES ("Easy"),("Medium"),("Hard"),("Pro Chef");
/*
https://stackoverflow.com/questions/1481476/when-to-use-on-update-cascade
comments is the child of recipes
one comment can have only 1 recipe but 1 recipe can have many comments ONE TO MANY
ON DELETE CASCADE to delete all comments if a recipe is deleted
*/
CREATE TABLE `recipe_comments`(
`CommentId` bigint unsigned NOT NULL AUTO_INCREMENT,
`Comment` varchar(1000) NOT NULL,
`UserId` varchar(255) NOT NULL,
`UserName` varchar(256) NOT NULL,
`RecipeId` bigint unsigned DEFAULT NULL,
PRIMARY KEY (`CommentId`),
KEY `RecipeId` (`RecipeId`),
CONSTRAINT `recipe_comments_ibfk_1` FOREIGN KEY (`RecipeId`) REFERENCES `recipes` (`RecipeId`) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE `recipe_usersaved`(
`UserSavedId` bigint unsigned NOT NULL AUTO_INCREMENT,
`UserId` varchar(255) NOT NULL,
`UserName` varchar(256) NOT NULL,
`RecipeId` bigint unsigned DEFAULT NULL,
PRIMARY KEY (`UserSavedId`),
KEY `RecipeId` (`RecipeId`),
CONSTRAINT `recipe_usersaved_ibfk_1` FOREIGN KEY (`RecipeId`) REFERENCES `recipes` (`RecipeId`) ON DELETE CASCADE ON UPDATE CASCADE
);
ALTER TABLE recipe_usersaved ADD RecipeTitle varchar(100) NOT NULL;