-
Notifications
You must be signed in to change notification settings - Fork 0
/
demoData.js
29 lines (28 loc) · 1003 Bytes
/
demoData.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
const Promise = require('bluebird');
const _ = require('lodash');
var models = require('./models');
uids = _.range(100);
models.sequelize.authenticate().then(() => {
return Promise.map(uids, uid => {
return models.User.create({
email: 'test@test.com',
password: '123456',
salt: ''
}).then(user => {
uid = user.id;
}).then(() => {
return models.Course.findAll();
}).then(courses => {
return _.sampleSize(courses, _.ceil(courses.length * 0.3));
}).then(courses => {
return Promise.map(courses, course => {
console.log(`insert ${course.id} with user ${uid}`);
return models.Comment.create({
rating: _.random(1, 5),
CourseId: course.id,
UserId: uid
});
}, { concurrency: 1 });
});
}, { concurrency: 1 });
}).done(() => models.sequelize.close());