-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdb_schema.sql
139 lines (135 loc) · 4.57 KB
/
db_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
CREATE TABLE strings
(
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
string VARCHAR NOT NULL
);
CREATE TABLE grades
(
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
aPlus INTEGER NOT NULL,
a INTEGER NOT NULL,
aMinus INTEGER NOT NULL,
bPlus INTEGER NOT NULL,
b INTEGER NOT NULL,
bMinus INTEGER NOT NULL,
cPlus INTEGER NOT NULL,
c INTEGER NOT NULL,
cMinus INTEGER NOT NULL,
dPlus INTEGER NOT NULL,
d INTEGER NOT NULL,
dMinus INTEGER NOT NULL,
f INTEGER NOT NULL,
cr INTEGER NOT NULL,
nc INTEGER NOT NULL,
p INTEGER NOT NULL,
w INTEGER NOT NULL,
i INTEGER NOT NULL,
nf INTEGER NOT NULL,
semesterId INTEGER NOT NULL REFERENCES strings (id),
subjectId INTEGER NOT NULL REFERENCES strings (id),
catalogNumberId INTEGER NOT NULL REFERENCES strings (id),
sectionId INTEGER NOT NULL REFERENCES strings (id),
instructor1Id INTEGER REFERENCES strings (id),
instructor2Id INTEGER REFERENCES strings (id),
instructor3Id INTEGER REFERENCES strings (id),
instructor4Id INTEGER REFERENCES strings (id),
instructor5Id INTEGER REFERENCES strings (id),
instructor6Id INTEGER REFERENCES strings (id)
);
CREATE VIEW grades_populated AS
SELECT grades.id AS gradesId,
grades.aPlus,
grades.a,
grades.aMinus,
grades.bPlus,
grades.b,
grades.bMinus,
grades.cPlus,
grades.c,
grades.cMinus,
grades.dPlus,
grades.d,
grades.dMinus,
grades.f,
grades.cr,
grades.nc,
grades.p,
grades.w,
grades.i,
grades.nf,
semester.string AS semester,
subject.string AS subject,
catalogNumber.string AS catalogNumber,
section.string AS section,
instructor1.string AS instructor1
FROM grades
INNER JOIN strings semester ON semester.id = grades.semesterId
INNER JOIN strings subject ON subject.id = grades.subjectId
INNER JOIN strings catalogNumber ON catalogNumber.id = grades.catalogNumberId
INNER JOIN strings section ON section.id = grades.sectionId
INNER JOIN strings instructor1 ON instructor1.id = grades.instructor1Id;
-- FIXME: grades_strings is no longer an appropriate name, since autocomplete now use autocomplete_strings
CREATE VIEW grades_strings(id,subject,courseSection,semester,instructor1) AS
SELECT gradesId,
subject,
catalogNumber || '.' || section,
semester,
instructor1
FROM grades_populated;
CREATE VIEW autocomplete_strings(priority,string,subject,courseSection,semester,instructor1) AS
-- CS 1337.001 Fall 2020 Firstname Lastname
SELECT 4,
subject || ' ' ||
catalogNumber || '.' ||
section || ' ' ||
semester || ' ' ||
instructor1,
subject,
catalogNumber || '.' || section,
semester,
instructor1
from grades_populated
UNION
-- CS 1337 Fall 2020 Firstname Lastname
SELECT 3,
subject || ' ' ||
catalogNumber || ' ' ||
semester || ' ' ||
instructor1,
subject,
catalogNumber,
semester,
instructor1
FROM grades_populated
UNION
-- CS 1337 Firstname Lastname
SELECT 2,
subject || ' ' ||
catalogNumber || ' ' ||
instructor1,
subject,
catalogNumber,
'',
instructor1
from grades_populated
UNION
-- CS 1337 Fall 2020
SELECT 1,
subject || ' ' ||
catalogNumber || ' ' ||
semester,
subject,
catalogNumber,
semester,
''
FROM grades_populated
UNION
-- CS 1337
SELECT 0,
subject || ' ' ||
catalogNumber,
subject,
catalogNumber,
'',
''
FROM grades_populated;