-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.sql
680 lines (534 loc) · 15.3 KB
/
schema.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
create table acad_object_groups
(
id integer not null,
name longname,
gtype acadobjectgrouptype not null,
glogic acadobjectgrouplogictype,
gdefby acadobjectgroupdeftype not null,
negated boolean default false,
parent integer,
definition textstring
);
alter table acad_object_groups
add primary key (id);
alter table acad_object_groups
add foreign key (parent) references acad_object_groups;
create table academic_standing
(
id integer not null,
standing shortname not null,
notes textstring
);
alter table academic_standing
add primary key (id);
create table affiliations
(
staff integer not null,
orgunit integer not null,
role integer not null,
isprimary boolean,
starting date not null,
ending date
);
alter table affiliations
add primary key (staff, orgunit, role, starting);
create table buildings
(
id integer not null,
unswid shortstring not null,
name longname not null,
campus campustype,
gridref char(4)
);
alter table buildings
add primary key (id);
alter table buildings
add unique (unswid);
create table class_types
(
id integer not null,
unswid shortstring not null,
name mediumname not null,
description mediumstring
);
alter table class_types
add primary key (id);
alter table class_types
add unique (unswid);
create table classes
(
id integer not null,
course integer not null,
room integer not null,
ctype integer not null,
dayofwk integer not null,
starttime integer not null,
endtime integer not null,
startdate date not null,
enddate date not null,
repeats integer
);
alter table classes
add primary key (id);
alter table classes
add foreign key (ctype) references class_types;
alter table classes
add constraint classes_dayofwk_check
check ((dayofwk >= 0) AND (dayofwk <= 6));
alter table classes
add constraint classes_endtime_check
check ((endtime >= 9) AND (endtime <= 23));
alter table classes
add constraint classes_starttime_check
check ((starttime >= 8) AND (starttime <= 22));
create table countries
(
id integer not null,
code char(3) not null,
name longname not null
);
alter table countries
add primary key (id);
alter table countries
add unique (code);
create table course_enrolments
(
student integer not null,
course integer not null,
mark integer,
grade gradetype,
stueval integer
);
alter table course_enrolments
add primary key (student, course);
alter table course_enrolments
add constraint course_enrolments_mark_check
check ((mark >= 0) AND (mark <= 100));
alter table course_enrolments
add constraint course_enrolments_stueval_check
check ((stueval >= 1) AND (stueval <= 6));
create table course_staff
(
course integer not null,
staff integer not null,
role integer not null
);
alter table course_staff
add primary key (course, staff, role);
create table courses
(
id integer not null,
subject integer not null,
semester integer not null,
homepage urlstring
);
alter table courses
add primary key (id);
alter table classes
add foreign key (course) references courses;
alter table course_enrolments
add foreign key (course) references courses;
alter table course_staff
add foreign key (course) references courses;
create table degree_types
(
id integer not null,
unswid shortname not null,
name mediumstring not null,
prefix mediumstring,
career careertype,
aqf_level integer
);
alter table degree_types
add primary key (id);
alter table degree_types
add unique (unswid);
alter table degree_types
add constraint degree_types_aqf_level_check
check (aqf_level > 0);
create table facilities
(
id integer not null,
description mediumstring not null
);
alter table facilities
add primary key (id);
create table orgunit_groups
(
owner integer not null,
member integer not null
);
alter table orgunit_groups
add primary key (owner, member);
create table orgunit_types
(
id integer not null,
name shortname not null
);
alter table orgunit_types
add primary key (id);
create table orgunits
(
id integer not null,
utype integer not null,
name mediumstring not null,
longname longstring,
unswid shortstring,
phone phonenumber,
email emailstring,
website urlstring,
starting date,
ending date
);
alter table orgunits
add primary key (id);
alter table affiliations
add foreign key (orgunit) references orgunits;
alter table orgunit_groups
add foreign key (member) references orgunits;
alter table orgunit_groups
add foreign key (owner) references orgunits;
alter table orgunits
add foreign key (utype) references orgunit_types;
create table people
(
id integer not null,
unswid integer,
password shortstring not null,
family longname,
given longname not null,
title shortname,
sortname longname not null,
name longname not null,
street longstring,
city mediumstring,
state mediumstring,
postcode shortstring,
country integer,
homephone phonenumber,
mobphone phonenumber,
email emailstring not null,
homepage urlstring,
gender char,
birthday date,
origin integer
);
alter table people
add primary key (id);
alter table people
add unique (unswid);
alter table people
add foreign key (country) references countries;
alter table people
add foreign key (origin) references countries;
alter table people
add constraint people_gender_check
check (gender = ANY (ARRAY ['m'::bpchar, 'f'::bpchar]));
create table program_degrees
(
id integer not null,
program integer,
dtype integer,
name longstring not null,
abbrev mediumstring
);
alter table program_degrees
add primary key (id);
alter table program_degrees
add foreign key (dtype) references degree_types;
create table program_enrolments
(
id integer not null,
student integer not null,
semester integer not null,
program integer not null,
wam real,
standing integer,
advisor integer,
notes textstring
);
alter table program_enrolments
add primary key (id);
alter table program_enrolments
add foreign key (standing) references academic_standing;
create table program_group_members
(
program integer not null,
ao_group integer not null
);
alter table program_group_members
add primary key (program, ao_group);
alter table program_group_members
add foreign key (ao_group) references acad_object_groups;
create table programs
(
id integer not null,
code char(4) not null,
name longname not null,
uoc integer,
offeredby integer,
career careertype,
duration integer,
description textstring,
firstoffer integer,
lastoffer integer
);
alter table programs
add primary key (id);
alter table program_degrees
add foreign key (program) references programs;
alter table program_enrolments
add foreign key (program) references programs;
alter table program_group_members
add foreign key (program) references programs;
alter table programs
add foreign key (offeredby) references orgunits;
alter table programs
add constraint programs_uoc_check
check (uoc >= 0);
create table room_facilities
(
room integer not null,
facility integer not null
);
alter table room_facilities
add primary key (room, facility);
alter table room_facilities
add foreign key (facility) references facilities;
create table room_types
(
id integer not null,
description mediumstring not null
);
alter table room_types
add primary key (id);
create table rooms
(
id integer not null,
unswid shortstring not null,
rtype integer,
name shortname not null,
longname longname,
building integer,
capacity integer
);
alter table rooms
add primary key (id);
alter table classes
add foreign key (room) references rooms;
alter table room_facilities
add foreign key (room) references rooms;
alter table rooms
add unique (unswid);
alter table rooms
add foreign key (building) references buildings;
alter table rooms
add foreign key (rtype) references room_types;
alter table rooms
add constraint rooms_capacity_check
check (capacity >= 0);
create table semesters
(
id integer not null,
unswid integer not null,
year courseyeartype,
term char(2) not null,
name shortname not null,
longname longname not null,
starting date not null,
ending date not null,
startbrk date,
endbrk date,
endwd date,
endenrol date,
census date
);
alter table semesters
add primary key (id);
alter table courses
add foreign key (semester) references semesters;
alter table program_enrolments
add foreign key (semester) references semesters;
alter table programs
add foreign key (firstoffer) references semesters;
alter table programs
add foreign key (lastoffer) references semesters;
alter table semesters
add unique (unswid);
alter table semesters
add constraint semesters_term_check
check (term = ANY (ARRAY ['S1'::bpchar, 'S2'::bpchar, 'X1'::bpchar, 'X2'::bpchar]));
create table staff
(
id integer not null,
office integer,
phone phonenumber,
employed date not null,
supervisor integer
);
alter table staff
add primary key (id);
alter table affiliations
add foreign key (staff) references staff;
alter table course_staff
add foreign key (staff) references staff;
alter table program_enrolments
add foreign key (advisor) references staff;
alter table staff
add foreign key (id) references people;
alter table staff
add foreign key (office) references rooms;
alter table staff
add foreign key (supervisor) references staff;
create table staff_role_classes
(
id char not null,
description shortstring
);
alter table staff_role_classes
add primary key (id);
create table staff_role_types
(
id char not null,
description shortstring
);
alter table staff_role_types
add primary key (id);
create table staff_roles
(
id integer not null,
rtype char,
rclass char,
name longstring not null,
description longstring
);
alter table staff_roles
add primary key (id);
alter table affiliations
add foreign key (role) references staff_roles;
alter table course_staff
add foreign key (role) references staff_roles;
alter table staff_roles
add foreign key (rclass) references staff_role_classes;
alter table staff_roles
add foreign key (rtype) references staff_role_types;
create table stream_enrolments
(
partof integer not null,
stream integer not null
);
alter table stream_enrolments
add primary key (partof, stream);
alter table stream_enrolments
add foreign key (partof) references program_enrolments;
create table stream_group_members
(
stream integer not null,
ao_group integer not null
);
alter table stream_group_members
add primary key (stream, ao_group);
alter table stream_group_members
add foreign key (ao_group) references acad_object_groups;
create table stream_types
(
id integer not null,
career careertype not null,
code char not null,
description shortstring not null
);
alter table stream_types
add primary key (id);
create table streams
(
id integer not null,
code char(6) not null,
name longname not null,
offeredby integer,
stype integer,
description textstring,
firstoffer integer,
lastoffer integer
);
alter table streams
add primary key (id);
alter table stream_enrolments
add foreign key (stream) references streams;
alter table stream_group_members
add foreign key (stream) references streams;
alter table streams
add foreign key (firstoffer) references semesters;
alter table streams
add foreign key (lastoffer) references semesters;
alter table streams
add foreign key (offeredby) references orgunits;
alter table streams
add foreign key (stype) references stream_types;
create table students
(
id integer not null,
stype varchar(5)
);
alter table students
add primary key (id);
alter table course_enrolments
add foreign key (student) references students;
alter table program_enrolments
add foreign key (student) references students;
alter table students
add foreign key (id) references people;
alter table students
add constraint students_stype_check
check ((stype)::text = ANY (ARRAY [('local'::character varying)::text, ('intl'::character varying)::text]));
create table subject_group_members
(
subject integer not null,
ao_group integer not null
);
alter table subject_group_members
add primary key (subject, ao_group);
alter table subject_group_members
add foreign key (ao_group) references acad_object_groups;
create table subjects
(
id integer not null,
code char(8) not null,
name mediumname not null,
longname longname,
uoc integer,
offeredby integer,
eftsload double precision,
career careertype,
syllabus textstring,
contacthpw double precision,
_excluded text,
excluded integer,
_equivalent text,
equivalent integer,
_prereq text,
prereq integer,
replaces integer,
firstoffer integer,
lastoffer integer
);
alter table subjects
add primary key (id);
alter table courses
add foreign key (subject) references subjects;
alter table subject_group_members
add foreign key (subject) references subjects;
alter table subjects
add foreign key (equivalent) references acad_object_groups;
alter table subjects
add foreign key (excluded) references acad_object_groups;
alter table subjects
add foreign key (firstoffer) references semesters;
alter table subjects
add foreign key (lastoffer) references semesters;
alter table subjects
add foreign key (offeredby) references orgunits;
alter table subjects
add foreign key (replaces) references subjects;
alter table subjects
add constraint subjects_uoc_check
check (uoc >= 0);