-
Notifications
You must be signed in to change notification settings - Fork 0
/
SQL-DDL.sql
206 lines (161 loc) · 5.55 KB
/
SQL-DDL.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
-- CREATE SCHEMA `csci5308_group14` ;
USE `csci5308_group14` ;
-- DROP schema `csci5308_group14` ;
DROP TABLE SurveyRuleMapper;
DROP TABLE TextResponses;
DROP TABLE NumericResponses;
DROP TABLE SurveyQuestionsMapper;
DROP TABLE Surveys;
DROP TABLE MultipleChoiceQuestions;
DROP TABLE AllQuestions;
DROP TABLE PasswordRules;
DROP TABLE PasswordHistory;
DROP TABLE SystemRoleMapper;
DROP TABLE CourseRoleMapper;
DROP TABLE SystemRoles;
DROP TABLE CourseRoles;
DROP TABLE Courses;
DROP TABLE Users;
DROP TABLE GroupFormationAlgorithmRules;
DROP TABLE QuestionTypes;
CREATE TABLE IF NOT EXISTS Users (
`user_id` VARCHAR(50) NOT NULL,
`password` VARCHAR(50) NOT NULL,
`first_name` VARCHAR(50) NOT NULL,
`last_name` VARCHAR(50),
`email` VARCHAR(50) NOT NULL,
`enabled` INT NOT NULL default 1,
PRIMARY KEY (`user_id`));
CREATE TABLE IF NOT EXISTS Courses (
`course_id` VARCHAR(50) NOT NULL,
`name` VARCHAR(50) NOT NULL,
`year` VARCHAR(50) NOT NULL,
`term` VARCHAR(50) NOT NULL,
`description` VARCHAR(200) NOT NULL,
`enabled` INT NOT NULL default 1,
PRIMARY KEY (`course_id`));
CREATE TABLE IF NOT EXISTS CourseRoles (
`role` VARCHAR(50) NOT NULL,
`description` VARCHAR(50) NOT NULL,
PRIMARY KEY (`role`));
CREATE TABLE IF NOT EXISTS SystemRoles (
`role` VARCHAR(50) NOT NULL,
`description` VARCHAR(50) NOT NULL,
PRIMARY KEY (`role`));
CREATE TABLE IF NOT EXISTS CourseRoleMapper (
`role_id` VARCHAR(50) NOT NULL,
`user_id` VARCHAR(50) NOT NULL,
`course_id` VARCHAR(50) NOT NULL,
CONSTRAINT FK_Course_Role FOREIGN KEY (role_id)
REFERENCES CourseRoles(role),
CONSTRAINT FK_Course_user_id FOREIGN KEY (user_id)
REFERENCES Users(user_id),
CONSTRAINT FK_Course_id FOREIGN KEY (course_id)
REFERENCES Courses(course_id),
PRIMARY KEY(user_id, course_id)
);
CREATE TABLE IF NOT EXISTS SystemRoleMapper (
`role_id` VARCHAR(50) NOT NULL,
`user_id` VARCHAR(50) NOT NULL,
CONSTRAINT FK_System_Role FOREIGN KEY (role_id)
REFERENCES SystemRoles(role),
CONSTRAINT FK_System_user_id FOREIGN KEY (user_id)
REFERENCES Users(user_id),
PRIMARY KEY(user_id)
);
CREATE TABLE IF NOT EXISTS PasswordRules (
`rule_id` VARCHAR(100) NOT NULL,
`regular_expression` VARCHAR(100) NOT NULL,
`min_match_count` int NOT NULL ,
`max_match_count` int NOT NULL ,
`description` VARCHAR(500) NOT NULL,
`enabled` INT NOT NULL default 1,
PRIMARY KEY(rule_id)
);
CREATE TABLE IF NOT EXISTS PasswordHistory (
`user_id` VARCHAR(50) NOT NULL,
`password` VARCHAR(50) NOT NULL,
`created_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT FK_Password_History_user_id FOREIGN KEY (user_id)
REFERENCES Users(user_id)
);
CREATE TABLE IF NOT EXISTS QuestionTypes (
`type` VARCHAR(50) NOT NULL,
`description` VARCHAR(200) NOT NULL,
PRIMARY KEY(type)
);
CREATE TABLE IF NOT EXISTS AllQuestions (
`question_id` int NOT NULL AUTO_INCREMENT,
`instructor_id` VARCHAR(50) NOT NULL,
`title` VARCHAR(50) NOT NULL,
`text` VARCHAR(500) NOT NULL,
`type` VARCHAR(50) NOT NULL,
`created_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT FK_Instructor_id FOREIGN KEY (instructor_id)
REFERENCES Users(user_id),
PRIMARY KEY(question_id)
);
CREATE TABLE IF NOT EXISTS MultipleChoiceQuestions (
`question_id` int NOT NULL,
`stored_as` int NOT NULL,
`display_text` VARCHAR(150) NOT NULL,
CONSTRAINT FK_Question_id FOREIGN KEY (question_id)
REFERENCES AllQuestions(question_id),
PRIMARY KEY(question_id, stored_as)
);
CREATE TABLE IF NOT EXISTS Surveys (
`survey_id` int NOT NULL AUTO_INCREMENT,
`course_id` VARCHAR(50) NOT NULL UNIQUE,
`published` INT NOT NULL default 0,
`group_size` INT NOT NULL,
CONSTRAINT FK_Survey_Course_id FOREIGN KEY (course_id)
REFERENCES Courses(course_id),
PRIMARY KEY(survey_id)
);
CREATE TABLE IF NOT EXISTS SurveyQuestionsMapper (
`response_id` int NOT NULL AUTO_INCREMENT,
`question_id` int NOT NULL,
`survey_id` int NOT NULL,
CONSTRAINT FK_Question_id_Mapping_Survey FOREIGN KEY (question_id)
REFERENCES AllQuestions(question_id),
CONSTRAINT FK_Survey_id FOREIGN KEY (survey_id)
REFERENCES Surveys(survey_id),
PRIMARY KEY(response_id)
);
CREATE TABLE IF NOT EXISTS NumericResponses (
`response_id` int NOT NULL ,
`student_id` VARCHAR(50) NOT NULL,
`answer` int NOT NULL,
CONSTRAINT FK_numeric_response_id FOREIGN KEY (response_id)
REFERENCES SurveyQuestionsMapper(response_id),
CONSTRAINT FK_numeric_response_Student_id FOREIGN KEY (student_id)
REFERENCES Users(user_id)
);
CREATE TABLE IF NOT EXISTS TextResponses (
`response_id` int NOT NULL ,
`student_id` VARCHAR(50) NOT NULL,
`answer` VARCHAR(500) NOT NULL,
CONSTRAINT FK_text_response_id FOREIGN KEY (response_id)
REFERENCES SurveyQuestionsMapper(response_id),
CONSTRAINT FK_text_response_Student_id FOREIGN KEY (student_id)
REFERENCES Users(user_id)
);
CREATE TABLE IF NOT EXISTS GroupFormationAlgorithmRules (
`rule_id` int NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) NOT NULL,
`question_type` VARCHAR(50) NOT NULL,
`description` VARCHAR(500) NOT NULL,
PRIMARY KEY(rule_id),
CONSTRAINT GFA_question_type FOREIGN KEY (question_type)
REFERENCES QuestionTypes(type)
);
CREATE TABLE IF NOT EXISTS SurveyRuleMapper (
`response_id` int NOT NULL ,
`rule_id` int NOT NULL,
`additional_info` VARCHAR(100) DEFAULT NULL,
CONSTRAINT Survey_Rule_response_id FOREIGN KEY (response_id)
REFERENCES SurveyQuestionsMapper(response_id),
CONSTRAINT Survey_Rule_rule_id FOREIGN KEY (rule_id)
REFERENCES GroupFormationAlgorithmRules(rule_id),
PRIMARY KEY(response_id)
);