-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.sql
143 lines (115 loc) · 4.54 KB
/
schema.sql
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
CREATE TABLE IF NOT EXISTS College
(
ID VARCHAR(10) PRIMARY KEY,
Name TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS CollegeAdmins
(
ClgID VARCHAR(10) NOT NULL,
userName VARCHAR(100) NOT NULL,
hashedPassword VARCHAR(100) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (ClgID, userName),
FOREIGN KEY (ClgID) REFERENCES College (ID) ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS Faculty
(
F_ID VARCHAR(10),
ClgID VARCHAR(10),
Name VARCHAR(100) NOT NULL,
Email VARCHAR(100) NOT NULL,
Phone VARCHAR(10) NOT NULL,
hashed_password VARCHAR(100) NOT NULL,
is_coordinator BOOLEAN DEFAULT FALSE NOT NULL,
PRIMARY KEY (F_ID, ClgID),
FOREIGN KEY (ClgID) REFERENCES College (ID) ON UPDATE CASCADE ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS Files
(
file_id SERIAL PRIMARY KEY,
file_data BYTEA,
file_name TEXT,
created_at timestamp DEFAULT current_timestamp
);
CREATE TABLE IF NOT EXISTS Exam
(
E_ID SERIAL,
ClgID VARCHAR(10),
title VARCHAR(100) NOT NULL,
start_date DATE NOT NULL,
end_date DATE NOT NULL,
seating_arrangement INT,
time_table INT,
created_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (E_ID, ClgID),
FOREIGN KEY (ClgID) REFERENCES College (ID) ON UPDATE CASCADE,
FOREIGN KEY (seating_arrangement) REFERENCES Files (file_id) ON UPDATE CASCADE ON DELETE SET NULL,
FOREIGN KEY (time_table) REFERENCES Files (file_id) ON UPDATE CASCADE ON DELETE SET NULL
);
/**
The table for which semesters the exam is conducting for
*/
CREATE TABLE ExamFor
(
ClgID VARCHAR(10) NOT NULL,
E_ID INT NOT NULL,
scheme INT NOT NULL,
semester INT NOT NULL,
PRIMARY KEY (ClgID, E_ID, scheme, semester),
FOREIGN KEY (E_ID, ClgID) REFERENCES Exam (E_ID, ClgID) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS Course
(
semester INT,
scheme INT,
name VARCHAR(100) NOT NULL,
course_id varchar(10),
created_at timestamp DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (scheme, course_id)
);
CREATE TYPE StatusTypes AS ENUM ('pending', 'success', 'under scrutiny', 'scrutinized', 'submitted');
CREATE TABLE IF NOT EXISTS QuestionPaper
(
f_id VARCHAR(10),
e_id INT NOT NULL,
clgID varchar(10) NOT NULL,
course_id varchar(10) NOT NULL,
scheme INT NOT NULL,
status StatusTypes DEFAULT 'pending' NOT NULL,
due_date DATE NOT NULL,
submitted_date DATE,
file_id INT,
created_date timestamp DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (scheme, course_id, e_id, clgID),
FOREIGN KEY (f_id, clgID) REFERENCES Faculty (F_ID, ClgID) ON UPDATE CASCADE,
FOREIGN KEY (file_id) REFERENCES Files (file_id) ON UPDATE CASCADE ON DELETE SET NULL,
FOREIGN KEY (e_id, clgID) REFERENCES Exam (E_ID, ClgID) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (course_id, scheme) REFERENCES Course (course_id, scheme) ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS Teaches
(
f_ID VARCHAR(10),
clg_ID VARCHAR(10),
course_ID VARCHAR(10),
scheme INT,
FOREIGN KEY (f_ID, clg_ID) REFERENCES Faculty (F_ID, ClgID) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (course_ID, scheme) REFERENCES Course (course_id, scheme) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS Scrutinizes
(
f_ID VARCHAR(10),
clg_ID VARCHAR(10),
course_ID VARCHAR(10),
scheme INT,
exam_ID INT,
file_id INT,
status StatusTypes DEFAULT 'pending' NOT NULL,
due_date DATE NOT NULL,
submitted_date DATE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (f_ID, clg_ID, course_ID, scheme, exam_ID),
FOREIGN KEY (file_id) REFERENCES Files (file_id) ON DELETE SET NULL ON UPDATE CASCADE,
FOREIGN KEY (f_ID, clg_ID) REFERENCES Faculty (F_ID, ClgID) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (course_ID, scheme) REFERENCES Course (course_id, scheme) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (exam_ID, clg_ID) REFERENCES Exam (E_ID, ClgID) ON DELETE CASCADE ON UPDATE CASCADE
)