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