Skip to content

Commit

Permalink
🐛 Make sure only clinical indices are deleted (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
evans-g-crsj authored Mar 27, 2024
1 parent 9ad703e commit f4055cb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//FIX: DUPLICATED CODE
/**
* npm run post-re-delete-indices-helper -- release:re_20231030_1
* npm run delete-clinical-indices-helper -- release:re_20231030_1
*
* */
import assert from 'node:assert/strict';
Expand Down Expand Up @@ -45,29 +45,40 @@ if (catIndicesResponse.statusCode !== 200) {
process.exit(1);
}

const releaseIndices = catIndicesResponse.body.map(x => x.index).sort();
assert(Array.isArray(releaseIndices) && releaseIndices.length > 0, 'No index found. Terminating');
const INDEX_CLINICAL_CATEGORIES = ['file', 'participant', 'study', 'biospecimen'];
const releaseClinicalIndices = catIndicesResponse.body
.map(x => x.index)
.filter(x => INDEX_CLINICAL_CATEGORIES.some(c => x.includes(c)))
.sort();
assert(Array.isArray(releaseClinicalIndices) && releaseClinicalIndices.length > 0, 'No index found. Terminating');

const INDEX_CATEGORIES = ['file', 'participant', 'study', 'biospecimen'];
const hasOnlyClinicalIndices = releaseIndices.every(r => {
// Extra check. Might not be needed, but cheap to test.
const hasOnlyClinicalIndices = releaseClinicalIndices.every(r => {
const indexPrefix = r.split('_')[0];
return INDEX_CATEGORIES.includes(indexPrefix);
return (
['gene', 'variant', 'member'].some(prefix => !r.startsWith(prefix)) &&
INDEX_CLINICAL_CATEGORIES.includes(indexPrefix)
);
});

assert(
hasOnlyClinicalIndices,
`Oops it seems like there is at least one type missing. Requires: ${INDEX_CATEGORIES.join(', ')}. Terminating`,
`Oops it seems like non-clinical indices are included. Requires: ${INDEX_CLINICAL_CATEGORIES.join(
', ',
)} only. Terminating`,
);

const displayIndicesQuestion = () =>
new Promise(resolve => {
userReadline.question(`${releaseIndices.length} were found. Do you want to display them y/n? > `, answer => {
const yes = answer === 'y';
if (yes) {
console.log(releaseIndices);
}
resolve();
});
userReadline.question(
`${releaseClinicalIndices.length} were found. Do you want to display them y/n? > `,
answer => {
const yes = answer === 'y';
if (yes) {
console.log(releaseClinicalIndices);
}
resolve();
},
);
});

isInteractive && (await displayIndicesQuestion());
Expand All @@ -84,13 +95,13 @@ if (proceedToDeletion) {
if (!isInteractive) {
const maxDisplay = 5;
console.log(
`Deleting ${releaseIndices.length} indices: ${releaseIndices.slice(0, maxDisplay).join(', ')} ${
releaseIndices.length > maxDisplay ? '...' : ''
}`,
`Deleting ${releaseClinicalIndices.length} indices: ${releaseClinicalIndices
.slice(0, maxDisplay)
.join(', ')} ${releaseClinicalIndices.length > maxDisplay ? '...' : ''}`,
);
}
const deleteResponse = await client.indices.delete({
index: releaseIndices,
index: releaseClinicalIndices,
});
console.log(deleteResponse.body);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"cbs": "npm run cleanAndBuild && npm start",
"admin-project": "node --experimental-modules=node --es-module-specifier-resolution=node admin/run.mjs",
"post-re-alias-helper": "node --experimental-modules=node --es-module-specifier-resolution=node admin/postReleaseIndicesToAliasesHelper.mjs",
"post-re-delete-indices-helper": "node --experimental-modules=node --es-module-specifier-resolution=node admin/deleteIndicesFromRelease.mjs"
"delete-clinical-indices-helper": "node --experimental-modules=node --es-module-specifier-resolution=node admin/deleteClinicalIndicesFromRelease.mjs"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit f4055cb

Please sign in to comment.