1
- 'use harmony'
2
-
3
1
const CommandRouter = require ( 'command-router' )
4
2
const cli = CommandRouter ( )
5
3
@@ -8,77 +6,74 @@ const common = require('../migrations/.common')
8
6
const es = require ( '../src/lib/elastic' )
9
7
10
8
cli . option ( { name : 'indexName' ,
11
- alias : 'i' ,
12
- default : config . elasticsearch . indices [ 0 ] ,
13
- type : String
9
+ alias : 'i' ,
10
+ default : config . elasticsearch . indices [ 0 ] ,
11
+ type : String
14
12
} )
15
13
16
14
cli . command ( 'rebuild' , ( ) => { // TODO: add parallel processing
17
- console . log ( '** Hello! I am going to rebuild EXISTINT ES index to fix the schema' )
18
- const originalIndex = cli . options . indexName
19
- const tempIndex = originalIndex + '_' + Math . round ( + new Date ( ) / 1000 )
20
-
21
- console . log ( '** Creating temporary index' + tempIndex )
22
- es . createIndex ( common . db , tempIndex , function ( err ) {
23
- if ( err ) {
24
- console . log ( err )
25
- }
15
+ console . log ( '** Hello! I am going to rebuild EXISTINT ES index to fix the schema' )
16
+ const originalIndex = cli . options . indexName
17
+ const tempIndex = originalIndex + '_' + Math . round ( + new Date ( ) / 1000 )
26
18
27
- console . log ( '** Putting the mappings on top of ' + tempIndex )
28
- es . putMappings ( common . db , tempIndex , function ( err ) {
19
+ console . log ( `** Creating temporary index ${ tempIndex } ` )
20
+ es . createIndex ( common . db , tempIndex , function ( err ) {
21
+ if ( err ) {
22
+ console . log ( err )
23
+ }
29
24
30
- console . log ( '** We will reindex ' + originalIndex + ' with the current schema' )
31
- es . reIndex ( common . db , originalIndex , tempIndex , function ( err ) {
32
- if ( err ) {
33
- console . log ( err )
34
- }
35
-
36
- console . log ( '** Removing the original index' )
37
- es . deleteIndex ( common . db , originalIndex , function ( err ) {
38
- if ( err ) {
39
- console . log ( err )
40
- }
25
+ console . log ( `** Putting the mappings on top of ${ tempIndex } ` )
26
+ es . putMappings ( common . db , tempIndex , function ( err ) {
41
27
42
- console . log ( '** Creating alias' )
43
- es . putAlias ( common . db , tempIndex , originalIndex , function ( err ) {
44
- console . log ( 'Done! Bye!' )
45
- process . exit ( 0 )
46
- } )
47
- } )
48
- } )
49
- } )
50
- } )
51
- } )
52
-
53
- cli . command ( 'new' , ( ) => { // TODO: add parallel processing
54
- console . log ( '** Hello! I am going to create NE ES index' )
55
- const indexName = cli . options . indexName
56
- es . createIndex ( common . db , indexName , function ( err ) {
28
+ console . log ( `** We will reindex ${ originalIndex } with the current schema` )
29
+ es . reIndex ( common . db , originalIndex , tempIndex , function ( err ) {
57
30
if ( err ) {
58
- console . log ( err )
31
+ console . log ( err )
59
32
}
60
33
61
- console . log ( 'Done! Bye!' )
34
+ console . log ( '** Removing the original index' )
35
+ es . deleteIndex ( common . db , originalIndex , function ( err ) {
36
+ if ( err ) {
37
+ console . log ( err )
38
+ }
39
+
40
+ console . log ( '** Creating alias' )
41
+ es . putAlias ( common . db , tempIndex , originalIndex , function ( err ) {
42
+ console . log ( 'Done! Bye!' )
43
+ process . exit ( 0 )
44
+ } )
45
+ } )
46
+ } )
62
47
} )
63
- } )
48
+ } )
49
+ } )
64
50
51
+ cli . command ( 'new' , ( ) => { // TODO: add parallel processing
52
+ console . log ( '** Hello! I am going to create NE ES index' )
53
+ const indexName = cli . options . indexName
54
+ es . createIndex ( common . db , indexName , function ( err ) {
55
+ if ( err ) {
56
+ console . log ( err )
57
+ }
65
58
59
+ console . log ( 'Done! Bye!' )
60
+ } )
61
+ } )
66
62
67
63
cli . on ( 'notfound' , ( action ) => {
68
- console . error ( ' I don\ 't know how to: ' + action )
64
+ console . error ( ` I don't know how to: ${ action } ` )
69
65
process . exit ( 1 )
70
66
} )
71
-
72
-
67
+
73
68
process . on ( 'unhandledRejection' , ( reason , p ) => {
74
- console . error ( ' Unhandled Rejection at: Promise' , p , ' reason:' , reason ) ;
75
- // application specific logging, throwing an error, or other logic here
76
- } ) ;
69
+ console . error ( ` Unhandled Rejection at: Promise ${ p } , reason: ${ reason } ` )
70
+ // application specific logging, throwing an error, or other logic here
71
+ } )
77
72
78
73
process . on ( 'uncaughtException' , function ( exception ) {
79
- console . error ( exception ) ; // to see your exception details in the console
80
- // if you are on production, maybe you can send the exception details to your
81
- // email as well ?
82
- } ) ;
74
+ console . error ( exception ) // to see your exception details in the console
75
+ // if you are on production, maybe you can send the exception details to your
76
+ // email as well ?
77
+ } )
83
78
84
- cli . parse ( process . argv ) ;
79
+ cli . parse ( process . argv )
0 commit comments