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
53 lines (44 loc) · 1.05 KB
/
99-fake-data.js
File metadata and controls
53 lines (44 loc) · 1.05 KB
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
'use strict'
import { default as debug } from 'debug'
import Promise from 'bluebird'
import faker from 'faker'
const log = debug('boot:99-fake.data')
module.exports = function (app) {
// Do not run if we are in codegen mode.
if (process.env.ENV === 'codegen') return
if (app.dataSources.db.name !== 'Memory' && !process.env.INITDB) {
return
}
const promises = []
const 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 (let model in structure) {
const options = structure[model]
log('Creating %s items for model %s', options.count, model)
for (let i = 0; i < options.count; i++) {
promises.push(app.models[model].createFakeData(faker))
}
}
}
Promise.all(promises).then(() => {
log('Creating fake data done!')
}).catch()
}