forked from Witvoet/loopback-example-mongodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
automigrate.js
38 lines (31 loc) · 792 Bytes
/
automigrate.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
var path = require('path');
var app = require(path.resolve(__dirname, '../server'));
var accounts = [
{
email: 'foo@bar.com',
createdAt: new Date(),
lastModifiedAt: new Date()
},
{
email: 'baz@qux.com',
createdAt: new Date(),
lastModifiedAt: new Date()
}
];
var dataSource = app.dataSources.accountDs;
dataSource.automigrate('Account', function(err) {
if (err) console.log(err);
var Account = app.models.Account;
var count = accounts.length;
accounts.forEach(function(account) {
Account.create(account, function(err, record) {
if (err) return console.log(err);
console.log('Record created:', record);
count--;
if (count === 0) {
console.log('done');
dataSource.disconnect();
}
});
});
});