File tree Expand file tree Collapse file tree 1 file changed +43
-1
lines changed Expand file tree Collapse file tree 1 file changed +43
-1
lines changed Original file line number Diff line number Diff line change 1
- require ( '../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 ( '../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
+ }
You can’t perform that action at this time.
0 commit comments