diff --git a/admin/deleteClinicalIndicesFromRelease.mjs b/admin/deleteClinicalIndicesFromRelease.mjs index e2d4af1..dac34c8 100644 --- a/admin/deleteClinicalIndicesFromRelease.mjs +++ b/admin/deleteClinicalIndicesFromRelease.mjs @@ -7,6 +7,7 @@ import assert from 'node:assert/strict'; import readline from 'readline'; import { Client } from '@elastic/elasticsearch'; import { esHost } from '../dist/src/env.js'; +import { cbKeepClinicalIndicesOnly } from './utils.mjs'; const args = process.argv.slice(2); const releaseArgument = args.find(a => a.startsWith('release:')) ?? ''; @@ -67,6 +68,19 @@ assert( )} only. Terminating`, ); +const rAllAliases = await client.cat.aliases({ + h: 'alias,index', + format: 'json', +}); + +assert(rAllAliases.statusCode === 200); + +const allAliases = rAllAliases.body; +const clinicalAliases = allAliases.filter(cbKeepClinicalIndicesOnly); + +const isAliased = clinicalAliases.some(x => x.index.includes(releaseTag)); +assert(!isAliased, `${releaseTag} is aliased`); + const displayIndicesQuestion = () => new Promise(resolve => { userReadline.question( diff --git a/admin/findClinicalIndicesUsage.mjs b/admin/findClinicalIndicesUsage.mjs index 9f018a5..a9238e1 100644 --- a/admin/findClinicalIndicesUsage.mjs +++ b/admin/findClinicalIndicesUsage.mjs @@ -4,6 +4,7 @@ import assert from 'node:assert/strict'; import { Client } from '@elastic/elasticsearch'; import { esHost } from '../dist/src/env.js'; +import { cbKeepClinicalIndicesOnly } from './utils.mjs'; const client = new Client({ node: esHost }); @@ -18,9 +19,6 @@ if (catIndicesResponse.statusCode !== 200) { process.exit(1); } -const cbKeepClinicalIndicesOnly = x => - ['file', 'biospecimen', 'participant', 'study'].some(stem => x.index.includes(stem)); - const clinicalIndices = catIndicesResponse.body.filter(cbKeepClinicalIndicesOnly); assert(Array.isArray(clinicalIndices) && clinicalIndices.length > 0, 'No index found. Terminating'); @@ -43,8 +41,8 @@ const clinicalIndicesNotAliased = clinicalIndices.filter(x => clinicalAliases.ev const unaliasedClinicalIndicesWithCreationDate = makeReleaseToCreationDate(clinicalIndicesNotAliased); // Make sure that no aliased index contains previously found unaliased releases. -const unaliasedReleases = unaliasedClinicalIndicesWithCreationDate.map(x => x.release) -assert(clinicalAliases.every(x => !unaliasedReleases.includes(`re_${x.index.split('re_')[1]}`))) +const unaliasedReleases = unaliasedClinicalIndicesWithCreationDate.map(x => x.release); +assert(clinicalAliases.every(x => !unaliasedReleases.includes(`re_${x.index.split('re_')[1]}`))); console.log(`===== Not Aliased`); diff --git a/admin/utils.mjs b/admin/utils.mjs new file mode 100644 index 0000000..08820c5 --- /dev/null +++ b/admin/utils.mjs @@ -0,0 +1,3 @@ +export const cbKeepClinicalIndicesOnly = x => + ['file', 'biospecimen', 'participant', 'study'].some(stem => x.index.includes(stem)); +