forked from colmena/colmena
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path99-fake-data.js
More file actions
51 lines (41 loc) · 972 Bytes
/
99-fake-data.js
File metadata and controls
51 lines (41 loc) · 972 Bytes
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
'use strict';
var log = require('debug')('boot:99-fake.data');
var faker = require('faker');
var Promise = require('bluebird');
module.exports = function (app) {
if (app.dataSources.db.name !== 'Memory' && !process.env.INITDB) {
return;
}
var promises = [];
var structure = {
Post: {
count: 15
},
Event: {
count: 15
},
Note: {
count: 15
},
Page: {
count: 15
}
};
if(app.dataSources.db.connected) {
createFakeData();
} else {
app.dataSources.db.once('connected', createFakeData);
}
function createFakeData() {
for (var model in structure) {
var options = structure[model];
log('Creating %s items for model %s', options.count, model);
for (var i = 0; i < options.count; i++) {
promises.push(app.models[model].createFakeData(faker));
}
}
}
Promise.all(promises).then(function () {
log('Creating fake data done!');
}).catch();
};