~azzar1/unity/add-show-desktop-key

936 by wagrant
userdb: Add the changes from migration 20080718-01 to users.sql. It was
1
CREATE SEQUENCE login_unixid_seq MINVALUE 1000 MAXVALUE 29999 START WITH 5000;
2
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
3
CREATE TABLE login (
446 by drtomc
users.sql: constrain the rolenm to be from a given set of roles.
4
    loginid     SERIAL PRIMARY KEY NOT NULL,
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
5
    login       VARCHAR UNIQUE NOT NULL,
446 by drtomc
users.sql: constrain the rolenm to be from a given set of roles.
6
    passhash    VARCHAR,
475 by mattgiuca
Commited some earlier changes to users.sql (not committed earlier due to
7
    state	VARCHAR NOT NULL CHECK (state in ('no_agreement', 'pending',
8
                                              'enabled', 'disabled')),
533 by mattgiuca
auth/authenticate: Much done!
9
    rolenm      VARCHAR NOT NULL CHECK (rolenm in ('anyone', 'student',
10
                                                   'marker', 'tutor',
11
                                                   'lecturer', 'admin')),
936 by wagrant
userdb: Add the changes from migration 20080718-01 to users.sql. It was
12
    unixid      INT UNIQUE DEFAULT nextval('login_unixid_seq') NOT NULL,
475 by mattgiuca
Commited some earlier changes to users.sql (not committed earlier due to
13
    nick        VARCHAR NOT NULL,
14
    pass_exp    TIMESTAMP,
15
    acct_exp    TIMESTAMP,
16
    last_login  TIMESTAMP,
522 by drtomc
Add quite a lot of stuff to get usrmgt happening.
17
    svn_pass    VARCHAR,
462 by mattgiuca
userdb/users.sql: Added email field to login.
18
    email       VARCHAR,
446 by drtomc
users.sql: constrain the rolenm to be from a given set of roles.
19
    fullname    VARCHAR NOT NULL,
631 by mattgiuca
users.sql: Added "settings" field to the login table.
20
    studentid   VARCHAR, -- may be null
21
    settings    VARCHAR
25 by drtomc
A bit more work on the userdb stuff.
22
);
23
935 by wagrant
userdb: Large changes:
24
-- Subjects
25
-- --------
26
816 by mattgiuca
users.sql: Updated database schema; split subject and offering tables.
27
CREATE TABLE subject (
28
    subjectid       SERIAL PRIMARY KEY NOT NULL,
29
    subj_code       VARCHAR UNIQUE NOT NULL,
30
    subj_name       VARCHAR NOT NULL,
916 by mattgiuca
userdb: Added constraints UNIQUE and NOT NULL to subjects.subj_short_name.
31
    subj_short_name VARCHAR UNIQUE NOT NULL,
817 by mattgiuca
users.sql: Moved url from offering to subjects table.
32
    url             VARCHAR
816 by mattgiuca
users.sql: Updated database schema; split subject and offering tables.
33
);
34
935 by wagrant
userdb: Large changes:
35
CREATE TABLE semester (
36
    semesterid  SERIAL PRIMARY KEY NOT NULL,
37
    year        CHAR(4) NOT NULL,
38
    semester    CHAR(1) NOT NULL,
39
    active      BOOL NOT NULL,
40
    UNIQUE (year, semester)
41
);
42
43
CREATE OR REPLACE FUNCTION deactivate_semester_enrolments_update()
44
RETURNS trigger AS '
45
    BEGIN
46
        IF OLD.active = true AND NEW.active = false THEN
47
            UPDATE enrolment SET active=false WHERE offeringid IN (
48
            SELECT offeringid FROM offering WHERE offering.semesterid = NEW.semesterid);
49
        END IF;
50
        RETURN NULL;
51
    END;
52
' LANGUAGE 'plpgsql';
53
54
CREATE TRIGGER deactivate_semester_enrolments
55
    AFTER UPDATE ON semester
56
    FOR EACH ROW EXECUTE PROCEDURE deactivate_semester_enrolments_update();
57
353 by drtomc
Start addressing sb's suggestions.
58
CREATE TABLE offering (
324 by drtomc
Should all be okay now.
59
    offeringid  SERIAL PRIMARY KEY NOT NULL,
816 by mattgiuca
users.sql: Updated database schema; split subject and offering tables.
60
    subject     INT4 REFERENCES subject (subjectid) NOT NULL,
935 by wagrant
userdb: Large changes:
61
    semesterid  INTEGER REFERENCES semester (semesterid) NOT NULL,
62
    groups_student_permissions  VARCHAR NOT NULL DEFAULT 'none',
63
    CHECK (groups_student_permissions in ('none', 'invite', 'create')),
64
    UNIQUE (subject, semesterid)
65
);
66
67
-- Projects and groups
68
-- -------------------
69
70
CREATE TABLE project_set (
71
    projectsetid  SERIAL PRIMARY KEY NOT NULL,
72
    offeringid    INTEGER REFERENCES offering (offeringid) NOT NULL,
73
    max_students_per_group  INTEGER NOT NULL DEFAULT 4
324 by drtomc
Should all be okay now.
74
);
75
355 by drtomc
Fix a few typos and glitches to actually create the ivle database.
76
CREATE TABLE project (
77
    projectid   SERIAL PRIMARY KEY NOT NULL,
78
    synopsis    VARCHAR,
79
    url         VARCHAR,
935 by wagrant
userdb: Large changes:
80
    projectsetid  INTEGER REFERENCES project_set (projectsetid) NOT NULL,
355 by drtomc
Fix a few typos and glitches to actually create the ivle database.
81
    deadline    TIMESTAMP
82
);
83
84
CREATE TABLE project_group (
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
85
    groupnm     VARCHAR NOT NULL,
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
86
    groupid     SERIAL PRIMARY KEY NOT NULL,
935 by wagrant
userdb: Large changes:
87
    projectsetid  INTEGER REFERENCES project_set (projectsetid) NOT NULL,
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
88
    nick        VARCHAR,
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
89
    createdby   INT4 REFERENCES login (loginid) NOT NULL,
90
    epoch       TIMESTAMP NOT NULL,
935 by wagrant
userdb: Large changes:
91
    UNIQUE (projectsetid, groupnm)
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
92
);
93
935 by wagrant
userdb: Large changes:
94
CREATE OR REPLACE FUNCTION check_group_namespacing_insertupdate()
95
RETURNS trigger AS '
96
    DECLARE
97
        oid INTEGER;
98
    BEGIN
99
        SELECT offeringid INTO oid FROM project_set WHERE project_set.projectsetid = NEW.projectsetid;
100
        PERFORM 1 FROM project_group, project_set WHERE project_group.projectsetid = project_set.projectsetid AND project_group.groupnm = NEW.groupnm;
101
        IF found THEN
102
            RAISE EXCEPTION ''a project group named % already exists in offering ID %'', NEW.groupnm, oid;
103
        END IF;
104
        RETURN NEW;
105
    END;
106
' LANGUAGE 'plpgsql';
107
108
CREATE TRIGGER check_group_namespacing
109
    BEFORE INSERT OR UPDATE ON project_group
110
    FOR EACH ROW EXECUTE PROCEDURE check_group_namespacing_insertupdate();
111
353 by drtomc
Start addressing sb's suggestions.
112
CREATE TABLE group_invitation (
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
113
    loginid     INT4 REFERENCES login (loginid) NOT NULL,
355 by drtomc
Fix a few typos and glitches to actually create the ivle database.
114
    groupid     INT4 REFERENCES project_group (groupid) NOT NULL,
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
115
    inviter     INT4 REFERENCES login (loginid) NOT NULL,
116
    invited     TIMESTAMP NOT NULL,
117
    accepted    TIMESTAMP,
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
118
    UNIQUE (loginid,groupid)
25 by drtomc
A bit more work on the userdb stuff.
119
);
120
353 by drtomc
Start addressing sb's suggestions.
121
CREATE TABLE group_member (
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
122
    loginid     INT4 REFERENCES login (loginid),
355 by drtomc
Fix a few typos and glitches to actually create the ivle database.
123
    groupid     INT4 REFERENCES project_group (groupid),
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
124
    PRIMARY KEY (loginid,groupid)
25 by drtomc
A bit more work on the userdb stuff.
125
);
126
127
CREATE TABLE enrolment (
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
128
    loginid     INT4 REFERENCES login (loginid),
353 by drtomc
Start addressing sb's suggestions.
129
    offeringid  INT4 REFERENCES offering (offeringid),
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
130
    result      INT,
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
131
    special_result VARCHAR,
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
132
    supp_result INT,
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
133
    special_supp_result VARCHAR,
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
134
    notes       VARCHAR,
935 by wagrant
userdb: Large changes:
135
    active      BOOL NOT NULL DEFAULT true,
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
136
    PRIMARY KEY (loginid,offeringid)
25 by drtomc
A bit more work on the userdb stuff.
137
);
138
935 by wagrant
userdb: Large changes:
139
CREATE OR REPLACE FUNCTION confirm_active_semester_insertupdate()
140
RETURNS trigger AS '
141
    DECLARE
142
        active BOOL;
143
    BEGIN
144
        SELECT semester.active INTO active FROM offering, semester WHERE offeringid=NEW.offeringid AND semester.semesterid = offering.semesterid;
145
        IF NOT active AND NEW.active = true THEN
146
            RAISE EXCEPTION ''cannot have active enrolment for % in offering %, as the semester is inactive'', NEW.loginid, NEW.offeringid;
147
        END IF;
148
        RETURN NEW;
149
    END;
150
' LANGUAGE 'plpgsql';
151
152
CREATE TRIGGER confirm_active_semester
153
    BEFORE INSERT OR UPDATE ON enrolment
154
    FOR EACH ROW EXECUTE PROCEDURE confirm_active_semester_insertupdate();
155
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
156
CREATE TABLE assessed (
157
    assessedid  SERIAL PRIMARY KEY NOT NULL,
158
    loginid     INT4 REFERENCES login (loginid),
355 by drtomc
Fix a few typos and glitches to actually create the ivle database.
159
    groupid     INT4 REFERENCES project_group (groupid),
915 by mattgiuca
Moved projectid from all tables using assessedid into the assessed table
160
    projectid   INT4 REFERENCES project (projectid) NOT NULL,
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
161
    -- exactly one of loginid and groupid must be non-null
162
    CHECK ((loginid IS NOT NULL AND groupid IS NULL)
163
        OR (loginid IS NULL AND groupid IS NOT NULL))
164
);
165
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
166
CREATE TABLE project_extension (
391 by drtomc
Fix a couple of typos.
167
    assessedid  INT4 REFERENCES assessed (assessedid) NOT NULL,
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
168
    deadline    TIMESTAMP NOT NULL,
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
169
    approver    INT4 REFERENCES login (loginid) NOT NULL,
170
    notes       VARCHAR
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
171
);
172
665 by drtomc
userdb: Add a submission table, as per our discussions.
173
CREATE TABLE project_submission (
174
    assessedid  INT4 REFERENCES assessed (assessedid) NOT NULL,
175
    path        VARCHAR NOT NULL,
176
    revision    INT4 NOT NULL
177
);
178
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
179
CREATE TABLE project_mark (
391 by drtomc
Fix a couple of typos.
180
    assessedid  INT4 REFERENCES assessed (assessedid) NOT NULL,
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
181
    componentid INT4,
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
182
    marker      INT4 REFERENCES login (loginid) NOT NULL,
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
183
    mark        INT,
184
    marked      TIMESTAMP,
185
    feedback    VARCHAR,
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
186
    notes       VARCHAR
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
187
);
281 by stevenbird
extensive updates based on data modelling discussion with Tom Conway
188
935 by wagrant
userdb: Large changes:
189
-- Worksheets
190
-- ----------
191
281 by stevenbird
extensive updates based on data modelling discussion with Tom Conway
192
CREATE TABLE problem (
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
193
    problemid   SERIAL PRIMARY KEY NOT NULL,
659 by drtomc
Add a little script for stuffing exercises into the database.
194
    identifier  VARCHAR UNIQUE NOT NULL,
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
195
    spec        VARCHAR
281 by stevenbird
extensive updates based on data modelling discussion with Tom Conway
196
);
197
725 by mattgiuca
The database now stores a cache of all the worksheets and what problems
198
CREATE TABLE worksheet (
199
    worksheetid SERIAL PRIMARY KEY NOT NULL,
200
    subject     VARCHAR NOT NULL,
201
    identifier  VARCHAR NOT NULL,
202
    assessable  BOOLEAN,
203
    mtime       TIMESTAMP,
204
    UNIQUE (subject, identifier)
205
);
206
207
CREATE TABLE worksheet_problem (
208
    worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
209
    problemid   INT4 REFERENCES problem (problemid) NOT NULL,
210
    optional    BOOLEAN,
211
    PRIMARY KEY (worksheetid, problemid)
212
);
213
353 by drtomc
Start addressing sb's suggestions.
214
CREATE TABLE problem_tag (
392 by drtomc
Fix another glitch.
215
    problemid   INT4 REFERENCES problem (problemid),
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
216
    tag         VARCHAR NOT NULL,
366 by drtomc
Somehow a couple of changed that address issues sb raised didn't get committed previously. Here they are.
217
    description VARCHAR,
218
    standard    BOOLEAN NOT NULL,
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
219
    added_by    INT4 REFERENCES login (loginid) NOT NULL,
319 by drtomc
Partial correctness for the user database schema. A few bits and pieces to go.
220
    date        TIMESTAMP NOT NULL,
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
221
    PRIMARY KEY (problemid,added_by,tag)
222
);
223
224
CREATE TABLE problem_test_case (
225
    problemid   INT4 REFERENCES problem (problemid) NOT NULL,
226
    testcaseid  SERIAL UNIQUE NOT NULL,
227
    testcase    VARCHAR,
228
    description VARCHAR,
229
    visibility  VARCHAR CHECK (visibility in ('public', 'protected', 'private'))
230
);
231
353 by drtomc
Start addressing sb's suggestions.
232
CREATE TABLE problem_test_case_tag (
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
233
    testcaseid  INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
234
    tag         VARCHAR NOT NULL,
235
    description VARCHAR,
366 by drtomc
Somehow a couple of changed that address issues sb raised didn't get committed previously. Here they are.
236
    standard    BOOLEAN NOT NULL,
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
237
    added_by    INT4 REFERENCES login (loginid) NOT NULL,
319 by drtomc
Partial correctness for the user database schema. A few bits and pieces to go.
238
    date        TIMESTAMP NOT NULL,
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
239
    PRIMARY KEY (testcaseid,added_by,tag)
281 by stevenbird
extensive updates based on data modelling discussion with Tom Conway
240
);
241
242
CREATE TABLE problem_attempt (
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
243
    problemid   INT4 REFERENCES problem (problemid) NOT NULL,
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
244
    loginid     INT4 REFERENCES login (loginid) NOT NULL,
319 by drtomc
Partial correctness for the user database schema. A few bits and pieces to go.
245
    date        TIMESTAMP NOT NULL,
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
246
    attempt     VARCHAR NOT NULL,
247
    complete    BOOLEAN NOT NULL,
1021 by dcoles
Database: Adds active column to problem_attempt table.
248
    active      BOOLEAN NOT NULL DEFAULT true,
319 by drtomc
Partial correctness for the user database schema. A few bits and pieces to go.
249
    PRIMARY KEY (problemid,loginid,date)
281 by stevenbird
extensive updates based on data modelling discussion with Tom Conway
250
);
251
697 by mattgiuca
users.sql: Added database table problem_save, for storing exercises that are
252
CREATE TABLE problem_save (
253
    problemid   INT4 REFERENCES problem (problemid) NOT NULL,
254
    loginid     INT4 REFERENCES login (loginid) NOT NULL,
255
    date        TIMESTAMP NOT NULL,
256
    text        VARCHAR NOT NULL,
257
    PRIMARY KEY (problemid,loginid)
258
);
259
324 by drtomc
Should all be okay now.
260
CREATE INDEX problem_attempt_index ON problem_attempt (problemid, loginid);
281 by stevenbird
extensive updates based on data modelling discussion with Tom Conway
261
262
CREATE TABLE problem_attempt_breakdown (
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
263
    problemid   INT4 REFERENCES problem (problemid) NOT NULL,
264
    testcaseid  INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
265
    loginid     INT4 REFERENCES login (loginid) NOT NULL,
319 by drtomc
Partial correctness for the user database schema. A few bits and pieces to go.
266
    date        TIMESTAMP NOT NULL,
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
267
    result      BOOLEAN
268
);
269
353 by drtomc
Start addressing sb's suggestions.
270
CREATE TABLE problem_prerequisite (
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
271
    parent      INT4 REFERENCES problem (problemid) NOT NULL,
272
    child       INT4 REFERENCES problem (problemid) NOT NULL,
273
    PRIMARY KEY (parent,child)
274
);
275