File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * Admin endpoint migrate data from DB to ES index.
3
+ *
4
+ * Waits until the operation is completed and returns result.
5
+ */
6
+ import _ from 'lodash' ;
7
+ import config from 'config' ;
8
+ import { middleware as tcMiddleware } from 'tc-core-library-js' ;
9
+ import esUtils from '../../utils/es' ;
10
+
11
+ const ES_METADATA_INDEX = config . get ( 'elasticsearchConfig.metadataIndexName' ) ;
12
+
13
+ const permissions = tcMiddleware . permissions ;
14
+
15
+ module . exports = [
16
+ permissions ( 'project.admin' ) ,
17
+ ( req , res , next ) => {
18
+ try {
19
+ const logger = req . log ;
20
+ logger . debug ( 'Entered Admin#migrateFromDb' ) ;
21
+
22
+ const indexName = _ . get ( req , 'body.indexName' ) ;
23
+ logger . debug ( 'indexName' , indexName ) ;
24
+
25
+ if ( ! indexName ) {
26
+ const apiErr = new Error ( '"indexName" is required.' ) ;
27
+ apiErr . status = 400 ;
28
+ throw apiErr ;
29
+ }
30
+
31
+ if ( indexName !== ES_METADATA_INDEX ) {
32
+ const apiErr = new Error ( `Only "indexName" === "${ ES_METADATA_INDEX } " is supported for now.` ) ;
33
+ apiErr . status = 400 ;
34
+ throw apiErr ;
35
+ }
36
+
37
+ esUtils . indexMetadata ( )
38
+ . then ( ( ) => {
39
+ res . status ( 200 ) . json ( { message : 'Data has been successfully migrated.' } ) ;
40
+ } )
41
+ . catch ( next ) ;
42
+ } catch ( err ) {
43
+ next ( err ) ;
44
+ }
45
+ } ,
46
+ ] ;
Original file line number Diff line number Diff line change @@ -85,6 +85,8 @@ router.route('/v5/projects/admin/es/createIndex')
85
85
. post ( require ( './admin/es-create-index' ) ) ;
86
86
router . route ( '/v5/projects/admin/es/deleteIndex' )
87
87
. delete ( require ( './admin/es-delete-index' ) ) ;
88
+ router . route ( '/v5/projects/admin/es/migrateFromDb' )
89
+ . patch ( require ( './admin/es-migrate-from-db' ) ) ;
88
90
router . route ( '/v5/projects/admin/es/project/index' )
89
91
. post ( require ( './admin/project-index-create' ) ) ;
90
92
router . route ( '/v5/projects/admin/es/project/remove' )
You can’t perform that action at this time.
0 commit comments