-
Notifications
You must be signed in to change notification settings - Fork 0
/
createDatastore.js
69 lines (58 loc) · 1.5 KB
/
createDatastore.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
const yaml = require('js-yaml');
const Datastore = require('./lib/Datastore');
const { required, notNull, string, foreignKey } = Datastore;
const createDatastore = data => {
const datastore = new Datastore();
datastore.define('language', [
// title
required('title'),
notNull('title'),
string('title'),
// parent
// TODO: Enforce type of 'language'.
foreignKey('parent'),
required('parent'),
]);
datastore.define('curriculum', [
// title
required('title'),
notNull('title'),
string('title'),
// parent
// TODO: Enforce type of 'curriculum'.
foreignKey('parent'),
required('parent'),
]);
datastore.define('definition-set');
datastore.define('definition', [
// title
required('title'),
notNull('title'),
string('title'),
// body
required('body'),
notNull('body'),
string('body'),
// language
required('language'),
notNull('language'),
foreignKey('language'),
// curriculum
foreignKey('curriculum'),
required('curriculum'),
// definitionSet
required('definitionSet'),
notNull('definitionSet'),
foreignKey('definitionSet'),
// TODO: Unique composite key for definitions:
// Datastore.unique(['language', 'curriculum', 'definitionSet']),
]);
data
.reduce((records, x) => records.concat(yaml.safeLoadAll(x)), [])
.forEach(record => {
datastore.create(record);
});
datastore.validate();
return datastore;
};
module.exports = createDatastore;