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

Commit 7f7a6cb

Browse files
Working db dump script and misc
1 parent 25ea241 commit 7f7a6cb

File tree

8 files changed

+243
-61
lines changed

8 files changed

+243
-61
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ Configuration for the application is at config/default.js and config/production.
3737
- UBAHN_AGGREGATE_TOPIC: Kafka topic that is used to combine all create, update and delete message(s)
3838
- ES.HOST: Elasticsearch host
3939
- ES.DOCUMENTS: Elasticsearch index, type and id mapping for resources.
40+
- ATTRIBUTE_GROUP_PIPELINE_ID: The pipeline id for enrichment with attribute group. Default is `attributegroup-pipeline`
41+
- SKILL_PROVIDER_PIPELINE_ID: The pipeline id for enrichment with skill provider. Default is `skillprovider-pipeline`
42+
- USER_PIPELINE_ID: The pipeline id for enrichment of user details. Default is `user-pipeline`
4043

4144
For `ES.DOCUMENTS` configuration, you will find multiple other configurations below it. Each has default values that you can override using the environment variables
4245

config/default.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ module.exports = {
5151
// ElasticSearch
5252
ES: {
5353
HOST: process.env.ES_HOST || 'http://localhost:9200',
54-
ENRICH_USER_PIPELINE_NAME: process.env.ENRICH_USER_PIPELINE_NAME || 'enrich_user',
5554
// es mapping: _index, _type, _id
5655
DOCUMENTS: {
5756
achievementprovider: {
@@ -64,7 +63,8 @@ module.exports = {
6463
},
6564
attributegroup: {
6665
index: process.env.ATTRIBUTE_GROUP_INDEX || 'attribute_group',
67-
type: '_doc'
66+
type: '_doc',
67+
pipelineId: process.env.ATTRIBUTE_GROUP_PIPELINE_ID || 'attributegroup-pipeline'
6868
},
6969
organization: {
7070
index: process.env.ORGANIZATION_INDEX || 'organization',
@@ -80,11 +80,13 @@ module.exports = {
8080
},
8181
skillprovider: {
8282
index: process.env.SKILL_PROVIDER_INDEX || 'skill_provider',
83-
type: '_doc'
83+
type: '_doc',
84+
pipelineId: process.env.SKILL_PROVIDER_PIPELINE_ID || 'skillprovider-pipeline'
8485
},
8586
user: {
8687
index: process.env.USER_INDEX || 'user',
87-
type: '_doc'
88+
type: '_doc',
89+
pipelineId: process.env.USER_PIPELINE_ID || 'user-pipeline'
8890
},
8991
// sub resources under user
9092
achievement: {

scripts/constants.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const topResources = {
1515
enrichFields: ['id', 'name', 'created', 'updated', 'createdBy', 'updatedBy']
1616
},
1717
pipeline: {
18-
id: 'skillprovider-pipeline',
18+
id: config.get('ES.DOCUMENTS.skillprovider.pipelineId'),
1919
field: 'skillProviderId',
2020
targetField: 'skillprovider',
2121
maxMatches: '1'
@@ -51,7 +51,7 @@ const topResources = {
5151
enrichFields: ['id', 'name', 'organizationId', 'created', 'updated', 'createdBy', 'updatedBy']
5252
},
5353
pipeline: {
54-
id: 'attributegroup-pipeline',
54+
id: config.get('ES.DOCUMENTS.attributegroup.pipelineId'),
5555
field: 'attributeGroupId',
5656
targetField: 'attributegroup',
5757
maxMatches: '1'
@@ -68,7 +68,7 @@ const topResources = {
6868
},
6969
ingest: {
7070
pipeline: {
71-
id: 'skillprovider-pipeline'
71+
id: config.get('ES.DOCUMENTS.skillprovider.pipelineId')
7272
}
7373
}
7474
},
@@ -83,21 +83,21 @@ const topResources = {
8383
},
8484
ingest: {
8585
pipeline: {
86-
id: 'attributegroup-pipeline'
86+
id: config.get('ES.DOCUMENTS.attributegroup.pipelineId')
8787
}
8888
}
8989
},
9090

9191
organization: {
9292
index: config.get('ES.DOCUMENTS.organization.index'),
93-
type: config.get('ES.DOCUMENTS.organization.type'),
93+
type: config.get('ES.DOCUMENTS.organization.type')
9494
},
9595

9696
user: {
9797
index: config.get('ES.DOCUMENTS.user.index'),
9898
type: config.get('ES.DOCUMENTS.user.type'),
9999
pipeline: {
100-
id: 'user-pipeline',
100+
id: config.get('ES.DOCUMENTS.user.pipelineId'),
101101
processors: [
102102
{
103103
referenceField: config.get('ES.DOCUMENTS.achievement.userField'),

scripts/db/dropAll.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,63 @@
44
const _ = require('lodash')
55
const models = require('../../src/models')
66
const logger = require('../../src/common/logger')
7-
const { topResources, modelToESIndexMapping } = require('../constants')
7+
const {
8+
topResources,
9+
organizationResources,
10+
modelToESIndexMapping
11+
} = require('../constants')
812
const { getESClient } = require('../../src/common/es-client')
913

1014
async function main () {
1115
const client = getESClient()
16+
17+
try {
18+
logger.info('Deleting all pipelines...')
19+
await client.ingest.deletePipeline({
20+
id: topResources.user.pipeline.id
21+
})
22+
await client.ingest.deletePipeline({
23+
id: topResources.skillprovider.pipeline.id
24+
})
25+
await client.ingest.deletePipeline({
26+
id: topResources.attributegroup.pipeline.id
27+
})
28+
logger.info('Successfully deleted')
29+
} catch (e) {
30+
console.error(e)
31+
logger.warn('Delete all ingest pipelines failed')
32+
}
33+
1234
const keys = Object.keys(models)
1335
for (let i = 0; i < keys.length; i++) {
1436
const key = keys[i]
1537
if (models[key].tableName) {
1638
const esResourceName = modelToESIndexMapping[key]
1739
try {
1840
if (_.includes(_.keys(topResources), esResourceName)) {
41+
if (topResources[esResourceName].enrich) {
42+
logger.info(`Deleting enrich policy for ${esResourceName}`)
43+
await client.enrich.deletePolicy({
44+
name: topResources[esResourceName].enrich.policyName
45+
})
46+
logger.info(`Successfully deleted enrich policy for ${esResourceName}`)
47+
}
48+
logger.info(`Deleting index for ${esResourceName}`)
1949
await client.indices.delete({
2050
index: topResources[esResourceName].index
2151
})
52+
logger.info(`Successfully deleted enrich policy for ${esResourceName}`)
53+
} else if (_.includes(_.keys(organizationResources), esResourceName)) {
54+
logger.info('Deleting enrich policy for organization')
55+
await client.enrich.deletePolicy({
56+
name: organizationResources[esResourceName].enrich.policyName
57+
})
58+
logger.info('Successfully deleted enrich policy for organization')
2259
}
2360

61+
logger.info(`Deleting data in QLDB for ${esResourceName}`)
2462
await models.DBHelper.clear(models[key])
63+
logger.info(`Successfully deleted data in QLDB for ${esResourceName}`)
2564
} catch (e) {
2665
console.error(e)
2766
logger.warn(`drop table ${key} failed`)

0 commit comments

Comments
 (0)