-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.sql
136 lines (120 loc) · 3.55 KB
/
database.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
DROP DATABASE IF EXISTS faculty_portal;
CREATE DATABASE faculty_portal;
\c faculty_portal;
-- The department table will have the names of the branches like: CSE, EE, ME etc
CREATE TABLE Department (
Id SERIAL,
name Varchar,
PRIMARY KEY( Id )
);
-- Faculty table will store the details of all the existing faculties,HODs,Cross-cutting Faculties, Director etc
CREATE TABLE Faculty (
Id SERIAL,
Name varchar,
dept_id Integer REFERENCES Department(Id),
Email varchar,
-- Profile varchar,
Joined_On timestamp,
Left_On timestamp,
username varchar UNIQUE,
password Varchar,
PRIMARY KEY( Id )
);
-- The table POR will store the names of all the position of responsibilties like Dean Academic Affairs, etc.
-- CREATE TABLE POR (
-- Id SERIAL,
-- Name Varchar,
-- PRIMARY KEY( Id )
-- );
-- This table will store positions like: "FACULTY","HOD","DEAN_ACADEMIC_AFFAIRS","DIRECTOR" etc
CREATE TABLE Positions (
Id Integer,
name Varchar UNIQUE,
PRIMARY KEY(Id)
);
-- This table will be used for dynamic routing
CREATE TABLE Route (
Id SERIAL,
applicant Integer REFERENCES Positions(Id),
sender Integer REFERENCES Positions(Id),
recipient Integer REFERENCES Positions(Id)
);
-- This table will have the position ID for each faculty to decide his role and get the corresponding route
CREATE TABLE Faculty_position (
Faculty_id Integer REFERENCES Faculty(Id) ,
Position_Id Integer REFERENCES Positions(Id),
PRIMARY KEY(Faculty_id)
);
-- The HOD table will store the IDs and tenures of the faculty who were appointed the HOD of a given department
CREATE TABLE HOD (
dept_id Integer REFERENCES Department(Id) ,
faculty_id Integer REFERENCES Faculty(Id) ,
start_date timestamp,
end_date timestamp,
PRIMARY KEY( dept_id )
);
-- This table will store the IDs of faculties who have served as HOD at some point in time
CREATE TABLE HOD_History (
id SERIAL,
dept_id Integer,
faculty_id Varchar,
start_date timestamp,
end_date timestamp,
rem_date timestamp
);
-- The HOD table will store the IDs and tenures of the faculty who are appointed at a POR
CREATE TABLE CCF (
id SERIAL,
Position_id Integer REFERENCES Positions(Id),
faculty_id Integer REFERENCES Faculty(Id),
start_date timestamp,
end_date timestamp,
PRIMARY KEY(id)
);
-- This table will store the IDs of faculties who have served at any POR at some point in time
CREATE TABLE CCF_History (
id SERIAL,
Position_id Integer,
faculty_id Integer,
start_date timestamp,
end_date timestamp,
rem_date timestamp
);
-- This table will store the details of leaves of corresponding leave IDs of faculty
CREATE TABLE Leaves (
Id Integer REFERENCES Faculty(Id),
leaves_left Integer,
total_leaves Integer,
cur_leave_app_id Integer,
next_year_leaves Integer,
next_year_leaves_left Integer,
PRIMARY KEY (Id)
);
CREATE TYPE STATUS AS ENUM( 'INITIATED', 'PENDING' , 'REJECTED' , 'APPROVED' , 'RENEW', 'MODIFIED');
-- The leave request table will store the IDs of the current leave applications
CREATE TABLE Leave_Request (
Id SERIAL ,
leave_id Integer REFERENCES Leaves(Id),
status STATUS,
start_date timestamp,
end_date timestamp,
--Insert
note text,
signed_on timestamp,
-- ------
comments text,
PRIMARY KEY(Id)
);
CREATE TABLE Leave_Approvals (
Id SERIAL,
LR_id Integer REFERENCES Leave_Request(Id),
applicant Integer REFERENCES Faculty(Id),
sender Integer REFERENCES Faculty(Id),
recipient Integer REFERENCES Faculty(Id),
-- Insert
recipient_pos Integer REFERENCES Positions(Id),
-- ----
status STATUS,
signed_On timestamp,
comments text
);