forked from PrairieLearn/PrairieLearn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
81 lines (75 loc) · 2.58 KB
/
index.js
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
var ERR = require('async-stacktrace');
var _ = require('lodash');
var fs = require('fs');
var path = require('path');
var async = require('async');
var pg = require('pg');
var error = require('../lib/error');
var logger = require('../lib/logger');
var sqldb = require('../lib/sqldb');
module.exports = {
init: function(callback) {
logger.verbose('Starting DB model initialization');
async.eachSeries([
// types
'enum_mode.sql',
'enum_question_type.sql',
'enum_role.sql',
'enum_role_add_none.sql',
'enum_course_role.sql',
'enum_submission_type.sql',
'enum_assessment_type.sql',
'enum_auth_action.sql',
'enum_grading_method.sql',
'enum_job_status.sql',
'enum_instance_question_status.sql',
// top-level tables
'users.sql',
'administrators.sql',
'courses.sql',
'course_permissions.sql',
// tables synced from git repo
'course_instances.sql',
'course_instance_access_rules.sql',
'topics.sql',
'questions.sql',
'tags.sql',
'question_tags.sql',
'assessment_sets.sql',
'assessments.sql',
'zones.sql',
'alternative_groups.sql',
'assessment_access_rules.sql',
'assessment_questions.sql',
// tables created during operation
'enrollments.sql',
'assessment_instances.sql',
'instance_questions.sql',
'variants.sql',
'submissions.sql',
'job_sequences.sql',
'jobs.sql',
// tables for logging
'assessment_state_logs.sql',
'assessment_score_logs.sql',
'access_logs.sql',
'variant_view_logs.sql',
'grading_logs.sql',
'question_score_logs.sql',
'audit_logs.sql',
], function(filename, callback) {
logger.verbose('Loading ' + filename);
fs.readFile(path.join(__dirname, filename), 'utf8', function(err, sql) {
sqldb.query(sql, [], function(err) {
if (err) error.addData(err, {sqlFile: filename});
if (ERR(err, callback)) return;
callback(null);
});
});
}, function(err) {
if (ERR(err, callback)) return;
logger.verbose('Successfully completed DB model initialization');
callback(null);
});
},
};