forked from strongloop/loopback-example-database
-
Notifications
You must be signed in to change notification settings - Fork 0
/
automigrate.js
37 lines (32 loc) · 926 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
// Copyright IBM Corp. 2015,2016. All Rights Reserved.
// Node module: loopback-example-database
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
var path = require('path');
var app = require(path.resolve(__dirname, '../server/server'));
var ds = app.datasources.accountDS;
ds.automigrate('Account', function(err) {
if (err) throw err;
var accounts = [
{
email: '[email protected]',
createdAt: new Date(),
lastModifiedAt: new Date(),
},
{
email: '[email protected]',
createdAt: new Date(),
lastModifiedAt: new Date(),
},
];
var count = accounts.length;
accounts.forEach(function(account) {
app.models.Account.create(account, function(err, model) {
if (err) throw err;
console.log('Created:', model);
count--;
if (count === 0)
ds.disconnect();
});
});
});