-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrecovery.ts
93 lines (88 loc) · 3.4 KB
/
recovery.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import AbstractCommand, { CommandOptions } from '../AbstractCommand';
import getElasticsearchClient from '../utils/es/EsUtils';
import { MAPPING_HISTORY_INDEX_NAME, MigrateIndex } from '../model/types';
import { cli } from 'cli-ux';
import StopWatch from '../utils/StopWatch';
export default class Recovery extends AbstractCommand {
static description = 'Delete failed migration history.';
static flags = {
...CommandOptions
};
async run() {
const { flags } = this.parse(Recovery);
await this.createHistoryIndex();
const elasticsearchClient = getElasticsearchClient(this.migrationConfig.elasticsearch);
const results = await elasticsearchClient
.search<MigrateIndex>({
index: MAPPING_HISTORY_INDEX_NAME,
body: {
size: 10000,
query: {
bool: {
must: [
{
term: {
index_name: {
value: flags.indexName
}
}
},
{
term: {
success: {
value: 'false'
}
}
}
]
}
}
}
})
.catch((reason) => {
cli.error(reason);
cli.exit(1);
});
if (results.length === 0) {
cli.info('No history of failed migrations.');
} else {
cli.info(`${results.length} errors in the migration history.`);
results.forEach((val) => cli.info(`Failed migration of ${val.script_name}.`));
cli.info('I will delete the above history.');
const sw = new StopWatch();
sw.start();
await elasticsearchClient
.deleteDocument({
index: MAPPING_HISTORY_INDEX_NAME,
body: {
query: {
bool: {
must: [
{
term: {
index_name: {
value: flags.indexName
}
}
},
{
term: {
success: {
value: 'false'
}
}
}
]
}
}
}
})
.catch((reason) => {
cli.error(reason);
cli.exit(1);
});
sw.stop();
cli.info(`Finished! (time: ${sw.read()} ms)`);
}
}
}