forked from dashersw/cote-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-db.js
37 lines (32 loc) · 771 Bytes
/
init-db.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
var models = require('./models');
var products = [
{
name: 'Fancy dish',
price: 1,
stock: 20
},
{
name: 'Healthy food',
price: 2,
stock: 20
},
{
name: 'Feast for kings',
price: 3,
stock: 20
}
];
module.exports = new Promise((resolve, reject) => {
models.drop(err => {
if (err) return console.log(err);
models.init(function(err) {
if (err) return console.log(err);
products.forEach(function(product) {
models.Product.create(product, function(err, product) {
console.log('Initialized', product.name);
resolve();
});
});
});
});
});