Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit baf6c04

Browse files
authored
Merge pull request #309 from afrisalyp/develop
create db model script more informative
2 parents cf9a65b + 24e45fb commit baf6c04

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

scripts/create-update-tables.js

+43-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,43 @@
1-
require('../src/models');
1+
/*
2+
* Copyright (c) 2017 TopCoder, Inc. All rights reserved.
3+
*/
4+
'use strict';
5+
6+
/**
7+
* Script to sync DB model to dynamodb service.
8+
* @author TCSCODER
9+
* @version 1.1
10+
*/
11+
12+
(async () => {
13+
try {
14+
console.log('Syncing database tables and indexes...');
15+
const models = require('../src/models');
16+
for (const key in models) {
17+
await pingTable(models[key]);
18+
}
19+
console.log('Remote tables is up to date.');
20+
} catch (e) {
21+
console.error(e);
22+
}
23+
})();
24+
25+
/**
26+
* Check if the table is exist
27+
* @param {Model} model the db model
28+
* @returns {Promise} the promise object
29+
*/
30+
async function pingTable(model) {
31+
return new Promise((resolve, reject) => {
32+
if (!(model.scan && typeof model.scan == 'function' && model.scan({}).exec)) {
33+
return resolve();
34+
}
35+
model.scan({id: 0}).exec((err, result) => {
36+
if (err) {
37+
console.log(`Table is not exists ${err}`);
38+
return reject(err);
39+
}
40+
return resolve();
41+
});
42+
});
43+
}

0 commit comments

Comments
 (0)