Skip to content

[BI-2995] Migrate parent ou ids in ou_level table to brapi ids - #19

Open
jloux-brapi wants to merge 3 commits into
feature/BI-2861from
feature/BI-2995
Open

[BI-2995] Migrate parent ou ids in ou_level table to brapi ids#19
jloux-brapi wants to merge 3 commits into
feature/BI-2861from
feature/BI-2995

Conversation

@jloux-brapi

@jloux-brapi jloux-brapi commented Jul 21, 2026

Copy link
Copy Markdown

Description

Story: BI-2995

New migration added to change existing bi-generated exref observation unit ids being stored in the observation_unit_level table to brapi db ids to conform to cache removal swaps.

Dependencies

Testing

Checklist:

@nickpalladino nickpalladino left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is another good one for @humsika to test

FROM observation_unit ou
JOIN observation_unit_external_references ouex ON ou.id = ouex.observation_unit_entity_id
JOIN external_reference ex ON ouex.external_references_id = ex.id
JOIN levels_and_parent_ou_bi_id ON ex.external_reference_id = levels_and_parent_ou_bi_id.parent_bi_ou_id

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just a thought, could we restrict this match to the BI observation-unit external_reference_source and verify that each level_id maps to exactly one ou.id?
external_reference_id is not unique in the schema, so matching on it alone could produce multiple parent OUs for the same level. In that case, PostgreSQL UPDATE ... FROM may select an unintended parent ID.

mol.ou_id::text
)
FROM ou_ids_matched_on_levels mol
WHERE observation_unit_level.id = mol.level_id No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could we add a migration assertion that fails when an expected parent relationship cannot be mapped, or when legacy parent IDs remain after this update? Rows missing a matching external reference are currently skipped silently, so Flyway could mark the migration successful while some records still contain the old BI-generated IDs.
I looked at the existing migration scripts, and we have a similar fail-fast assertion in V005.002__migrate_observation_levels.sql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants