Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(migration): introduce conditionality and continue indexing on failure #7742

Merged
merged 11 commits into from
Oct 8, 2024

Conversation

makelicious
Copy link
Collaborator

Issue:
When running migrations, we assume arrays always contain at least one item. This results to failure during the process.

Fix:
Introduce conditional checks to remaining files, even if they might work without 99% of the time.


Issue:
Reindexing throws an error when single document fails to be indexed to elasticsearch.
Most likely the implicit schema that gets created prevents some of the items being added.

Fix:
Allow elasticsearch to drop the documents but keep track of them.

Copy link

github-actions bot commented Oct 8, 2024

Oops! Looks like you forgot to update the changelog. When updating CHANGELOG.md, please consider the following:

  • Changelog is read by country implementors who might not always be familiar with all technical details of OpenCRVS. Keep language high-level, user friendly and avoid technical references to internals.
  • Answer "What's new?", "Why was the change made?" and "Why should I care?" for each change.
  • If it's a breaking change, include a migration guide answering "What do I need to do to upgrade?".

@ocrvs-bot
Copy link
Collaborator

Your environment is deployed to https://fixmigration-errors.opencrvs.dev

@@ -67,7 +67,7 @@ export const up = async (db: Db, client: MongoClient) => {
const operationHistoriesData =
searchResult &&
searchResult.body.hits.hits.length > 0 &&
searchResult.body.hits.hits[0]._source?.operationHistories
searchResult.body.hits.hits?.[0]?._source?.operationHistories
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably this is safer instead of the three lines here?

searchResult?.body?.hits?.hits?.[0]?._source?.operationHistories

@@ -150,10 +151,10 @@ async function updateEventLocationIdOrJurisdictionIds(db: Db, elasticDoc: any) {
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be similar to packages/migration/src/migrations/hearth/20221110092434-add_identifiers_DOB_gender_location.ts?

@@ -150,10 +151,10 @@ async function updateEventLocationIdOrJurisdictionIds(db: Db, elasticDoc: any) {
)

if (locationDoc.length > 0) {
if (locationDoc[0].type.coding[0].code === 'HEALTH_FACILITY') {
body.eventLocationId = locationDoc[0].id
if (locationDoc?.[0]?.type?.coding?.[0]?.code === 'HEALTH_FACILITY') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (locationDoc?.[0]?.type?.coding?.[0]?.code === 'HEALTH_FACILITY') {
if (locationDoc[0].type?.coding?.[0]?.code === 'HEALTH_FACILITY') {

as we just asserted that length is greater than zero 😄

@naftis naftis changed the title Fix/migration errors fix(migration): introduce conditionality and continue indexing on failure Oct 8, 2024
@makelicious makelicious merged commit 4480507 into develop Oct 8, 2024
38 of 40 checks passed
makelicious added a commit that referenced this pull request Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants