-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.sql
More file actions
103 lines (84 loc) · 2.62 KB
/
Copy pathdata.sql
File metadata and controls
103 lines (84 loc) · 2.62 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
DROP TABLE IF EXISTS codecooler, admin, mentor, student, mentor_class, class, transaction, inventory, item CASCADE;
CREATE TABLE codecooler (
codecooler_id serial PRIMARY KEY,
first_name text,
last_name text,
email text,
login text,
password text,
account_type text
);
INSERT INTO codecooler (First_name, last_name, email, login, password, account_type)
VALUES ('Eliza', 'Golec', 'email@gmail.com', 'eliza', 'password', 'student');
CREATE TABLE admin (
admin_id serial PRIMARY KEY,
codecooler_id integer,
FOREIGN KEY (codecooler_id) REFERENCES codecooler (codecooler_id)
ON DELETE CASCADE ON UPDATE NO ACTION
);
INSERT INTO admin (codecooler_id)
VALUES (1);
CREATE TABLE mentor (
mentor_id serial PRIMARY KEY,
codecooler_id integer,
FOREIGN KEY (codecooler_id) REFERENCES codecooler (codecooler_id)
ON DELETE CASCADE ON UPDATE NO ACTION
);
INSERT INTO mentor (codecooler_id)
VALUES (1);
CREATE TABLE class (
class_id serial PRIMARY KEY,
name text
);
INSERT INTO class (name)
VALUES ('webRoom');
CREATE TABLE student (
student_id serial PRIMARY KEY,
codecooler_id integer,
class_id integer,
FOREIGN KEY (codecooler_id) REFERENCES codecooler (codecooler_id)
ON DELETE CASCADE ON UPDATE NO ACTION,
FOREIGN KEY (class_id) REFERENCES class (class_id)
ON DELETE CASCADE ON UPDATE NO ACTION
);
INSERT INTO student (codecooler_id, class_id)
VALUES (1, 1);
CREATE TABLE mentor_class (
mentor_id integer,
class_id integer ,
PRIMARY KEY (mentor_id, class_id),
FOREIGN KEY (mentor_id) REFERENCES mentor (mentor_id)
ON DELETE CASCADE ON UPDATE NO ACTION,
FOREIGN KEY (class_id) REFERENCES class (class_id)
ON DELETE CASCADE ON UPDATE NO ACTION
);
INSERT INTO mentor_class (mentor_id, class_id)
VALUES (1, 1);
CREATE TABLE item (
item_id serial PRIMARY KEY,
name text,
description text,
price integer,
category text
);
INSERT INTO item (name, decription, price, category)
VALUES ('name', 'description', 25, 'single');
CREATE TABLE transaction (
transaction_id serial PRIMARY KEY,
student_id integer,
item_id integer,
amount integer,
FOREIGN KEY (student_id) REFERENCES student (student_id)
ON DELETE NO ACTION ON UPDATE NO ACTION,
FOREIGN KEY (item_id) REFERENCES item (item_id)
ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE inventory (
student_id integer,
item_id integer,
PRIMARY KEY (student_id, item_id),
FOREIGN KEY (student_id) REFERENCES student (student_id)
ON DELETE CASCADE ON UPDATE NO ACTION,
FOREIGN KEY (item_id) REFERENCES item (item_id)
ON DELETE NO ACTION ON UPDATE NO ACTION
);