3
CREATE OR REPLACE FUNCTION valid_url_name(name text) RETURNS boolean AS
6
RETURN name ~ E'^[a-z0-9][a-z0-9_\+\.\-]*$';
10
CREATE OR REPLACE FUNCTION valid_login_name(name text) RETURNS boolean AS
13
RETURN name ~ E'^[a-z0-9][a-z0-9@_\+\.\-]*$';
15
$$ LANGUAGE 'plpgsql';
17
2
CREATE SEQUENCE login_unixid_seq MINVALUE 1000 MAXVALUE 29999 START WITH 5000;
19
4
CREATE TABLE login (
20
5
loginid SERIAL PRIMARY KEY NOT NULL,
21
login VARCHAR UNIQUE NOT NULL CHECK (valid_login_name(login)),
6
login VARCHAR UNIQUE NOT NULL,
23
8
state VARCHAR NOT NULL CHECK (state in ('no_agreement', 'pending',
24
9
'enabled', 'disabled'))
46
28
subjectid SERIAL PRIMARY KEY NOT NULL,
47
29
subj_code VARCHAR UNIQUE NOT NULL,
48
30
subj_name VARCHAR NOT NULL,
49
subj_short_name VARCHAR UNIQUE NOT NULL CHECK (valid_url_name(subj_short_name))
31
subj_short_name VARCHAR UNIQUE NOT NULL,
52
35
CREATE TABLE semester (
53
36
semesterid SERIAL PRIMARY KEY NOT NULL,
54
year TEXT NOT NULL CHECK (valid_url_name(year)),
55
url_name TEXT NOT NULL CHECK (valid_url_name(url_name)),
57
display_name TEXT NOT NULL,
37
year CHAR(4) NOT NULL,
38
semester CHAR(1) NOT NULL,
58
39
state TEXT NOT NULL CHECK (state IN ('disabled', 'past',
59
40
'current', 'future')) DEFAULT 'current',
60
UNIQUE (year, url_name),
41
UNIQUE (year, semester)
64
44
CREATE TABLE offering (
65
45
offeringid SERIAL PRIMARY KEY NOT NULL,
66
46
subject INT4 REFERENCES subject (subjectid) NOT NULL,
67
47
semesterid INTEGER REFERENCES semester (semesterid) NOT NULL,
70
show_worksheet_marks BOOLEAN NOT NULL DEFAULT false,
71
worksheet_cutoff TIMESTAMP,
72
48
groups_student_permissions VARCHAR NOT NULL DEFAULT 'none',
73
49
CHECK (groups_student_permissions in ('none', 'invite', 'create')),
74
50
UNIQUE (subject, semesterid)
86
62
CREATE TABLE project (
87
63
projectid SERIAL PRIMARY KEY NOT NULL,
88
short_name TEXT NOT NULL CHECK (valid_url_name(short_name)),
64
short_name TEXT NOT NULL,
89
65
name TEXT NOT NULL,
120
96
FOR EACH ROW EXECUTE PROCEDURE check_project_namespacing_insertupdate();
122
98
CREATE TABLE project_group (
123
groupnm VARCHAR NOT NULL CHECK (valid_url_name(groupnm)),
99
groupnm VARCHAR NOT NULL,
124
100
groupid SERIAL PRIMARY KEY NOT NULL,
125
101
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
186
162
OR (loginid IS NULL AND groupid IS NOT NULL))
189
CREATE UNIQUE INDEX assessed_loginid_key ON assessed(loginid, projectid) WHERE loginid IS NOT NULL;
190
CREATE UNIQUE INDEX assessed_groupid_key ON assessed(groupid, projectid) WHERE groupid IS NOT NULL;
192
165
CREATE TABLE project_extension (
193
166
extensionid SERIAL PRIMARY KEY,
194
167
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
168
deadline TIMESTAMP NOT NULL,
196
169
approver INT4 REFERENCES login (loginid) NOT NULL,
222
194
CREATE TABLE exercise (
223
identifier TEXT PRIMARY KEY CHECK (valid_url_name(identifier)),
195
identifier TEXT PRIMARY KEY,
225
197
description TEXT,
226
description_xhtml_cache TEXT,
233
204
CREATE TABLE worksheet (
234
205
worksheetid SERIAL PRIMARY KEY,
235
206
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
236
identifier TEXT NOT NULL CHECK (valid_url_name(identifier)),
207
identifier TEXT NOT NULL,
237
208
name TEXT NOT NULL,
238
209
data TEXT NOT NULL,
239
data_xhtml_cache TEXT,
240
210
assessable BOOLEAN NOT NULL,
241
published BOOLEAN NOT NULL DEFAULT true,
242
211
seq_no INT4 NOT NULL,
243
212
format TEXT NOT NUll,
244
213
UNIQUE (offeringid, identifier)