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

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