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

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