-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathschema.sql
More file actions
executable file
·94 lines (76 loc) · 1.95 KB
/
Copy pathschema.sql
File metadata and controls
executable file
·94 lines (76 loc) · 1.95 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
DROP DATABASE IF EXISTS pantry;
CREATE DATABASE pantry;
USE pantry;
CREATE TABLE users (
id INT NOT NULL AUTO_INCREMENT,
name TEXT NOT NULL,
password TEXT NOT NULL,
PRIMARY KEY(id)
);
CREATE TABLE ingredients (
id INT NOT NULL AUTO_INCREMENT,
ingredient TEXT NOT NULL,
user_id INT NOT NULL,
PRIMARY KEY(id),
FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE recipes (
id INT NOT NULL AUTO_INCREMENT,
recipe JSON NOT NULL,
user_id INT NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id),
PRIMARY KEY(id)
);
CREATE TABLE users_ingredients (
id INT NOT NULL AUTO_INCREMENT,
user_id INT NOT NULL,
ingredient_id INT NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id)
ON DELETE CASCADE
ON UPDATE CASCADE,
FOREIGN KEY (ingredient_id) REFERENCES ingredients(id)
ON DELETE CASCADE
ON UPDATE CASCADE,
PRIMARY KEY(id)
);
CREATE TABLE users_recipes (
id INT NOT NULL AUTO_INCREMENT,
user_id INT NOT NULL,
recipe_id INT NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id)
ON DELETE CASCADE
ON UPDATE CASCADE,
FOREIGN KEY (recipe_id) REFERENCES recipes(id)
ON DELETE CASCADE
ON UPDATE CASCADE,
PRIMARY KEY(id)
);
/* TEST DATA */
INSERT INTO users (name, password)
VALUES ('joshawesome12', 'butter98');
INSERT INTO users (name, password)
VALUES ('Ghostcoder8', 'h@xx');
INSERT INTO recipes (recipe, user_id)
VALUES (
'{
"name": "soup",
"ingredients": ["chicken", "broth", "noodles"]
}', 1
);
INSERT INTO recipes (recipe, user_id)
VALUES (
'{
"name": "chicken",
"ingredients": ["chicken breast", "oil", "salt"]
}', 2
);
INSERT INTO users_recipes (recipe_id, user_id)
VALUES (2, 1);
INSERT INTO users_recipes (recipe_id, user_id)
VALUES (1, 1);
/* Execute this file from the command line by typing:
* mysql -u root -p < server/schema.sql
* to create the database and the tables.
*
* To make queries to the database using the terminal, type:
* mysql -u root -p */