8
8
state VARCHAR NOT NULL CHECK (state in ('no_agreement', 'pending',
9
9
'enabled', 'disabled'))
10
10
DEFAULT 'no_agreement',
11
admin BOOLEAN NOT NULL DEFAULT false,
11
rolenm VARCHAR NOT NULL CHECK (rolenm in ('anyone', 'student',
13
'lecturer', 'admin')),
12
14
unixid INT UNIQUE DEFAULT nextval('login_unixid_seq') NOT NULL,
13
15
nick VARCHAR NOT NULL,
14
16
pass_exp TIMESTAMP,
36
38
semesterid SERIAL PRIMARY KEY NOT NULL,
37
39
year CHAR(4) NOT NULL,
38
40
semester CHAR(1) NOT NULL,
39
state TEXT NOT NULL CHECK (state IN ('disabled', 'past',
40
'current', 'future')) DEFAULT 'current',
41
42
UNIQUE (year, semester)
45
CREATE OR REPLACE FUNCTION deactivate_semester_enrolments_update()
48
IF OLD.active = true AND NEW.active = false THEN
49
UPDATE enrolment SET active=false WHERE offeringid IN (
50
SELECT offeringid FROM offering WHERE offering.semesterid = NEW.semesterid);
56
CREATE TRIGGER deactivate_semester_enrolments
57
AFTER UPDATE ON semester
58
FOR EACH ROW EXECUTE PROCEDURE deactivate_semester_enrolments_update();
44
60
CREATE TABLE offering (
45
61
offeringid SERIAL PRIMARY KEY NOT NULL,
46
62
subject INT4 REFERENCES subject (subjectid) NOT NULL,
56
72
CREATE TABLE project_set (
57
73
projectsetid SERIAL PRIMARY KEY NOT NULL,
58
74
offeringid INTEGER REFERENCES offering (offeringid) NOT NULL,
59
max_students_per_group INTEGER
75
max_students_per_group INTEGER NOT NULL DEFAULT 4
62
78
CREATE TABLE project (
63
79
projectid SERIAL PRIMARY KEY NOT NULL,
64
short_name TEXT NOT NULL,
68
82
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
72
CREATE OR REPLACE FUNCTION check_project_namespacing_insertupdate()
77
IF TG_OP = ''UPDATE'' THEN
78
IF NEW.projectsetid = OLD.projectsetid AND NEW.short_name = OLD.short_name THEN
82
SELECT offeringid INTO oid FROM project_set WHERE project_set.projectsetid = NEW.projectsetid;
83
PERFORM 1 FROM project, project_set
84
WHERE project_set.offeringid = oid AND
85
project.projectsetid = project_set.projectsetid AND
86
project.short_name = NEW.short_name;
88
RAISE EXCEPTION ''a project named % already exists in offering ID %'', NEW.short_name, oid;
94
CREATE TRIGGER check_project_namespacing
95
BEFORE INSERT OR UPDATE ON project
96
FOR EACH ROW EXECUTE PROCEDURE check_project_namespacing_insertupdate();
98
86
CREATE TABLE project_group (
99
87
groupnm VARCHAR NOT NULL,
100
88
groupid SERIAL PRIMARY KEY NOT NULL,
141
129
CREATE TABLE enrolment (
142
130
loginid INT4 REFERENCES login (loginid),
143
131
offeringid INT4 REFERENCES offering (offeringid),
144
role TEXT NOT NULL CHECK (role IN ('student', 'tutor',
145
'lecturer')) DEFAULT 'student',
147
133
special_result VARCHAR,
152
138
PRIMARY KEY (loginid,offeringid)
141
CREATE OR REPLACE FUNCTION confirm_active_semester_insertupdate()
146
SELECT semester.active INTO active FROM offering, semester WHERE offeringid=NEW.offeringid AND semester.semesterid = offering.semesterid;
147
IF NOT active AND NEW.active = true THEN
148
RAISE EXCEPTION ''cannot have active enrolment for % in offering %, as the semester is inactive'', NEW.loginid, NEW.offeringid;
152
' LANGUAGE 'plpgsql';
154
CREATE TRIGGER confirm_active_semester
155
BEFORE INSERT OR UPDATE ON enrolment
156
FOR EACH ROW EXECUTE PROCEDURE confirm_active_semester_insertupdate();
155
158
CREATE TABLE assessed (
156
159
assessedid SERIAL PRIMARY KEY NOT NULL,
157
160
loginid INT4 REFERENCES login (loginid),
165
168
CREATE TABLE project_extension (
166
extensionid SERIAL PRIMARY KEY,
167
169
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
168
170
deadline TIMESTAMP NOT NULL,
169
171
approver INT4 REFERENCES login (loginid) NOT NULL,
173
175
CREATE TABLE project_submission (
174
submissionid SERIAL PRIMARY KEY,
175
176
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
176
177
path VARCHAR NOT NULL,
177
revision INT4 NOT NULL,
178
date_submitted TIMESTAMP NOT NULL,
179
submitter INT4 REFERENCES login (loginid) NOT NULL
178
revision INT4 NOT NULL
182
181
CREATE TABLE project_mark (