~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',
1112 by matt.giuca
userdb/users.sql: Fixed two syntax errors. Jeepers!
11
    admin       BOOLEAN NOT NULL DEFAULT false,
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,
1112 by matt.giuca
userdb/users.sql: Fixed two syntax errors. Jeepers!
39
    state       TEXT NOT NULL CHECK (state IN ('disabled', 'past',
40
                                    'current', 'future')) DEFAULT 'current',
935 by wagrant
userdb: Large changes:
41
    UNIQUE (year, semester)
42
);
43
353 by drtomc
Start addressing sb's suggestions.
44
CREATE TABLE offering (
324 by drtomc
Should all be okay now.
45
    offeringid  SERIAL PRIMARY KEY NOT NULL,
816 by mattgiuca
users.sql: Updated database schema; split subject and offering tables.
46
    subject     INT4 REFERENCES subject (subjectid) NOT NULL,
935 by wagrant
userdb: Large changes:
47
    semesterid  INTEGER REFERENCES semester (semesterid) NOT NULL,
48
    groups_student_permissions  VARCHAR NOT NULL DEFAULT 'none',
49
    CHECK (groups_student_permissions in ('none', 'invite', 'create')),
50
    UNIQUE (subject, semesterid)
51
);
52
53
-- Projects and groups
54
-- -------------------
55
56
CREATE TABLE project_set (
57
    projectsetid  SERIAL PRIMARY KEY NOT NULL,
58
    offeringid    INTEGER REFERENCES offering (offeringid) NOT NULL,
1165.1.45 by William Grant
Remove the NOT NULL and default from project_set.max_students_per_group.
59
    max_students_per_group  INTEGER
324 by drtomc
Should all be okay now.
60
);
61
355 by drtomc
Fix a few typos and glitches to actually create the ivle database.
62
CREATE TABLE project (
63
    projectid   SERIAL PRIMARY KEY NOT NULL,
1165.1.3 by William Grant
Add NOT NULL name and short_name columns to project.
64
    short_name  TEXT NOT NULL,
65
    name        TEXT NOT NULL,
66
    synopsis    TEXT,
67
    url         TEXT,
935 by wagrant
userdb: Large changes:
68
    projectsetid  INTEGER REFERENCES project_set (projectsetid) NOT NULL,
355 by drtomc
Fix a few typos and glitches to actually create the ivle database.
69
    deadline    TIMESTAMP
70
);
71
1165.1.3 by William Grant
Add NOT NULL name and short_name columns to project.
72
CREATE OR REPLACE FUNCTION check_project_namespacing_insertupdate()
73
RETURNS trigger AS '
74
    DECLARE
75
        oid INTEGER;
76
    BEGIN
77
        IF TG_OP = ''UPDATE'' THEN
78
            IF NEW.projectsetid = OLD.projectsetid AND NEW.short_name = OLD.short_name THEN
79
                RETURN NEW;
80
            END IF;
81
        END IF;
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;
87
        IF found THEN
88
            RAISE EXCEPTION ''a project named % already exists in offering ID %'', NEW.short_name, oid;
89
        END IF;
90
        RETURN NEW;
91
    END;
92
' LANGUAGE 'plpgsql';
93
94
CREATE TRIGGER check_project_namespacing
95
    BEFORE INSERT OR UPDATE ON project
96
    FOR EACH ROW EXECUTE PROCEDURE check_project_namespacing_insertupdate();
97
355 by drtomc
Fix a few typos and glitches to actually create the ivle database.
98
CREATE TABLE project_group (
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
99
    groupnm     VARCHAR NOT NULL,
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
100
    groupid     SERIAL PRIMARY KEY NOT NULL,
935 by wagrant
userdb: Large changes:
101
    projectsetid  INTEGER REFERENCES project_set (projectsetid) NOT NULL,
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
102
    nick        VARCHAR,
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
103
    createdby   INT4 REFERENCES login (loginid) NOT NULL,
104
    epoch       TIMESTAMP NOT NULL,
935 by wagrant
userdb: Large changes:
105
    UNIQUE (projectsetid, groupnm)
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
106
);
107
935 by wagrant
userdb: Large changes:
108
CREATE OR REPLACE FUNCTION check_group_namespacing_insertupdate()
109
RETURNS trigger AS '
110
    DECLARE
111
        oid INTEGER;
112
    BEGIN
113
        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
114
        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:
115
        IF found THEN
116
            RAISE EXCEPTION ''a project group named % already exists in offering ID %'', NEW.groupnm, oid;
117
        END IF;
118
        RETURN NEW;
119
    END;
120
' LANGUAGE 'plpgsql';
121
122
CREATE TRIGGER check_group_namespacing
123
    BEFORE INSERT OR UPDATE ON project_group
124
    FOR EACH ROW EXECUTE PROCEDURE check_group_namespacing_insertupdate();
125
353 by drtomc
Start addressing sb's suggestions.
126
CREATE TABLE group_invitation (
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
127
    loginid     INT4 REFERENCES login (loginid) NOT NULL,
355 by drtomc
Fix a few typos and glitches to actually create the ivle database.
128
    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. :-)
129
    inviter     INT4 REFERENCES login (loginid) NOT NULL,
130
    invited     TIMESTAMP NOT NULL,
131
    accepted    TIMESTAMP,
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
132
    UNIQUE (loginid,groupid)
25 by drtomc
A bit more work on the userdb stuff.
133
);
134
353 by drtomc
Start addressing sb's suggestions.
135
CREATE TABLE group_member (
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
136
    loginid     INT4 REFERENCES login (loginid),
355 by drtomc
Fix a few typos and glitches to actually create the ivle database.
137
    groupid     INT4 REFERENCES project_group (groupid),
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
138
    PRIMARY KEY (loginid,groupid)
25 by drtomc
A bit more work on the userdb stuff.
139
);
140
141
CREATE TABLE enrolment (
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
142
    loginid     INT4 REFERENCES login (loginid),
353 by drtomc
Start addressing sb's suggestions.
143
    offeringid  INT4 REFERENCES offering (offeringid),
1101 by William Grant
Privileges (apart from admin) are now offering-local, not global.
144
    role        TEXT NOT NULL CHECK (role IN ('student', 'tutor',
145
                                              'lecturer')) DEFAULT 'student',
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
146
    result      INT,
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
147
    special_result VARCHAR,
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
148
    supp_result INT,
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
149
    special_supp_result VARCHAR,
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
150
    notes       VARCHAR,
935 by wagrant
userdb: Large changes:
151
    active      BOOL NOT NULL DEFAULT true,
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
152
    PRIMARY KEY (loginid,offeringid)
25 by drtomc
A bit more work on the userdb stuff.
153
);
154
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
155
CREATE TABLE assessed (
156
    assessedid  SERIAL PRIMARY KEY NOT NULL,
157
    loginid     INT4 REFERENCES login (loginid),
355 by drtomc
Fix a few typos and glitches to actually create the ivle database.
158
    groupid     INT4 REFERENCES project_group (groupid),
915 by mattgiuca
Moved projectid from all tables using assessedid into the assessed table
159
    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. :-)
160
    -- exactly one of loginid and groupid must be non-null
161
    CHECK ((loginid IS NOT NULL AND groupid IS NULL)
162
        OR (loginid IS NULL AND groupid IS NOT NULL))
163
);
164
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
165
CREATE TABLE project_extension (
1165.1.2 by William Grant
Add serial primary keys to project_{extension,submission}.
166
    extensionid SERIAL PRIMARY KEY,
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 (
1165.1.2 by William Grant
Add serial primary keys to project_{extension,submission}.
174
    submissionid SERIAL PRIMARY KEY,
665 by drtomc
userdb: Add a submission table, as per our discussions.
175
    assessedid  INT4 REFERENCES assessed (assessedid) NOT NULL,
176
    path        VARCHAR NOT NULL,
1165.1.1 by Matt Giuca
users.sql: Added to project_submission: 'date_submitted'.
177
    revision    INT4 NOT NULL,
1165.1.42 by William Grant
Record who submitted each submission.
178
    date_submitted TIMESTAMP NOT NULL,
179
    submitter   INT4 REFERENCES login (loginid) NOT NULL
665 by drtomc
userdb: Add a submission table, as per our discussions.
180
);
181
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
182
CREATE TABLE project_mark (
391 by drtomc
Fix a couple of typos.
183
    assessedid  INT4 REFERENCES assessed (assessedid) NOT NULL,
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
184
    componentid INT4,
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
185
    marker      INT4 REFERENCES login (loginid) NOT NULL,
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
186
    mark        INT,
187
    marked      TIMESTAMP,
188
    feedback    VARCHAR,
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
189
    notes       VARCHAR
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
190
);
281 by stevenbird
extensive updates based on data modelling discussion with Tom Conway
191
935 by wagrant
userdb: Large changes:
192
-- Worksheets
193
-- ----------
1099.1.195 by William Grant
Rename problem to exercise in the DB.
194
CREATE TABLE exercise (
1099.1.145 by Nick Chadwick
Minor updates to the sql for the userdb
195
    identifier  TEXT PRIMARY KEY,
1099.1.114 by Nick Chadwick
Modified the database so that exercises are now stored in the database, rather
196
    name        TEXT,
197
    description TEXT,
198
    partial     TEXT,
199
    solution    TEXT,
200
    include     TEXT,
201
    num_rows    INT4
281 by stevenbird
extensive updates based on data modelling discussion with Tom Conway
202
);
203
725 by mattgiuca
The database now stores a cache of all the worksheets and what problems
204
CREATE TABLE worksheet (
1099.1.145 by Nick Chadwick
Minor updates to the sql for the userdb
205
    worksheetid SERIAL PRIMARY KEY,
206
    offeringid  INT4 REFERENCES offering (offeringid) NOT NULL,
1099.1.185 by William Grant
A few almost-final worksheet/exercise schema changes. Mainly cosmetic.
207
    identifier  TEXT NOT NULL,
1099.4.1 by Nick Chadwick
Working on putting worksheets into the database.
208
    name        TEXT NOT NULL,
1099.4.3 by Nick Chadwick
Updated the tutorial service, to now allow users to edit worksheets
209
    data        TEXT NOT NULL,
210
    assessable  BOOLEAN NOT NULL,
1099.1.184 by William Grant
Fix a column name mismatch between the migration and primary schema.
211
    seq_no      INT4 NOT NULL,
1099.4.3 by Nick Chadwick
Updated the tutorial service, to now allow users to edit worksheets
212
    format      TEXT NOT NUll,
1099.1.145 by Nick Chadwick
Minor updates to the sql for the userdb
213
    UNIQUE (offeringid, identifier)
725 by mattgiuca
The database now stores a cache of all the worksheets and what problems
214
);
215
1099.1.195 by William Grant
Rename problem to exercise in the DB.
216
CREATE TABLE worksheet_exercise (
217
    ws_ex_id        SERIAL PRIMARY KEY,
1099.4.3 by Nick Chadwick
Updated the tutorial service, to now allow users to edit worksheets
218
    worksheetid     INT4 REFERENCES worksheet (worksheetid) NOT NULL,
1099.1.195 by William Grant
Rename problem to exercise in the DB.
219
    exerciseid      TEXT REFERENCES exercise (identifier) NOT NULL,
1099.1.185 by William Grant
A few almost-final worksheet/exercise schema changes. Mainly cosmetic.
220
    seq_no          INT4 NOT NULL,
221
    active          BOOLEAN NOT NULL DEFAULT true,
222
    optional        BOOLEAN NOT NULL,
1099.1.195 by William Grant
Rename problem to exercise in the DB.
223
    UNIQUE (worksheetid, exerciseid)
725 by mattgiuca
The database now stores a cache of all the worksheets and what problems
224
);
225
1099.1.195 by William Grant
Rename problem to exercise in the DB.
226
CREATE TABLE exercise_attempt (
354 by drtomc
Addressed the rest of sb's suggestions. No doubt this will lead to more suggestions. :-)
227
    loginid     INT4 REFERENCES login (loginid) NOT NULL,
1099.1.195 by William Grant
Rename problem to exercise in the DB.
228
    ws_ex_id    INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
319 by drtomc
Partial correctness for the user database schema. A few bits and pieces to go.
229
    date        TIMESTAMP NOT NULL,
1099.1.185 by William Grant
A few almost-final worksheet/exercise schema changes. Mainly cosmetic.
230
    attempt     TEXT NOT NULL,
296 by drtomc
Almost SQLized the database stuff from yesterday's discussion with sb.
231
    complete    BOOLEAN NOT NULL,
1021 by dcoles
Database: Adds active column to problem_attempt table.
232
    active      BOOLEAN NOT NULL DEFAULT true,
1099.1.195 by William Grant
Rename problem to exercise in the DB.
233
    PRIMARY KEY (loginid, ws_ex_id, date)
281 by stevenbird
extensive updates based on data modelling discussion with Tom Conway
234
);
235
1099.1.195 by William Grant
Rename problem to exercise in the DB.
236
CREATE TABLE exercise_save (
697 by mattgiuca
users.sql: Added database table problem_save, for storing exercises that are
237
    loginid     INT4 REFERENCES login (loginid) NOT NULL,
1099.1.195 by William Grant
Rename problem to exercise in the DB.
238
    ws_ex_id    INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
697 by mattgiuca
users.sql: Added database table problem_save, for storing exercises that are
239
    date        TIMESTAMP NOT NULL,
1099.1.145 by Nick Chadwick
Minor updates to the sql for the userdb
240
    text        TEXT NOT NULL,
1099.1.195 by William Grant
Rename problem to exercise in the DB.
241
    PRIMARY KEY (loginid, ws_ex_id)
697 by mattgiuca
users.sql: Added database table problem_save, for storing exercises that are
242
);
243
1099.1.114 by Nick Chadwick
Modified the database so that exercises are now stored in the database, rather
244
CREATE TABLE test_suite (
1099.1.145 by Nick Chadwick
Minor updates to the sql for the userdb
245
    suiteid     SERIAL PRIMARY KEY,
1099.1.195 by William Grant
Rename problem to exercise in the DB.
246
    exerciseid  TEXT REFERENCES exercise (identifier) NOT NULL,
1099.1.114 by Nick Chadwick
Modified the database so that exercises are now stored in the database, rather
247
    description TEXT,
248
    seq_no      INT4,
1099.1.141 by Nick Chadwick
Updated the exercises to be loaded from the database, not a local file.
249
    function    TEXT,
1099.1.145 by Nick Chadwick
Minor updates to the sql for the userdb
250
    stdin       TEXT
1099.1.114 by Nick Chadwick
Modified the database so that exercises are now stored in the database, rather
251
);
252
253
CREATE TABLE test_case (
1099.1.145 by Nick Chadwick
Minor updates to the sql for the userdb
254
    testid          SERIAL PRIMARY KEY,
1099.1.141 by Nick Chadwick
Updated the exercises to be loaded from the database, not a local file.
255
    suiteid         INT4 REFERENCES test_suite (suiteid) NOT NULL,
256
    passmsg         TEXT,
257
    failmsg         TEXT,
258
    test_default    TEXT,
1099.1.145 by Nick Chadwick
Minor updates to the sql for the userdb
259
    seq_no          INT4
1099.1.141 by Nick Chadwick
Updated the exercises to be loaded from the database, not a local file.
260
);
261
1099.1.195 by William Grant
Rename problem to exercise in the DB.
262
CREATE TABLE suite_variable (
1099.1.145 by Nick Chadwick
Minor updates to the sql for the userdb
263
    varid       SERIAL PRIMARY KEY,
1099.1.114 by Nick Chadwick
Modified the database so that exercises are now stored in the database, rather
264
    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.
265
    var_name    TEXT,
266
    var_value   TEXT,
267
    var_type    TEXT NOT NULL,
268
    arg_no      INT4
269
);
270
1099.1.195 by William Grant
Rename problem to exercise in the DB.
271
CREATE TABLE test_case_part (
1099.1.145 by Nick Chadwick
Minor updates to the sql for the userdb
272
    partid          SERIAL PRIMARY KEY,
1099.1.141 by Nick Chadwick
Updated the exercises to be loaded from the database, not a local file.
273
    testid          INT4 REFERENCES test_case (testid) NOT NULL,
1099.1.145 by Nick Chadwick
Minor updates to the sql for the userdb
274
    part_type       TEXT NOT NULL,
1099.1.141 by Nick Chadwick
Updated the exercises to be loaded from the database, not a local file.
275
    test_type       TEXT,
276
    data            TEXT,
277
    filename        TEXT
1099.1.114 by Nick Chadwick
Modified the database so that exercises are now stored in the database, rather
278
);
1099.1.142 by Nick Chadwick
Fixed a slight issue with the migration and the users.sql files not
279
COMMIT;