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

SDIT-2021 Cater for retries to the mapping creation by performing an upsert #369

Merged
merged 1 commit into from
Oct 31, 2024

Conversation

mikehalmamoj
Copy link
Contributor

No description provided.

Comment on lines +81 to +84
@PutMapping("/migration")
@Operation(
summary = "Creates or updates a prison person migration mapping",
description = "Creates or updates a mapping between nomis prisoner numbers and prison person history ids. Requires ROLE_NOMIS_PRISONPERSON",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When testing we found that sometimes a prisoner migration is retried despite all records being created in DPS and the mapping service. As DPS is idempotent and just overwrites the previous migration we need the same behaviour in the mapping service, hence switching to a PUT.

Comment on lines +46 to +70
private suspend fun PrisonPersonMigrationMappingRequest.update(): PrisonPersonMigrationMapping =
template.update<PrisonPersonMigrationMapping>()
.inTable("prison_person_migration_mapping")
.matching(
query(
where("nomis_prisoner_number").`is`(nomisPrisonerNumber)
.and(where("migration_type").`is`(migrationType))
.and(where("label").`is`(label)),
),
)
.apply(update("dps_ids", dpsIds.toString()))
.awaitSingle()
.let { find()!! }

private suspend fun PrisonPersonMigrationMappingRequest.insert(): PrisonPersonMigrationMapping =
template.insert<PrisonPersonMigrationMapping>()
.using(
PrisonPersonMigrationMapping(
nomisPrisonerNumber = nomisPrisonerNumber,
migrationType = migrationType,
dpsIds = dpsIds.toString(),
label = label,
),
)
.awaitSingle()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Spring data R2DBC still doesn't support composite entity keys so we needed another way. I thought I'd try out the template instead.

@mikehalmamoj mikehalmamoj enabled auto-merge (squash) October 30, 2024 17:00
Copy link
Contributor

@andymarke andymarke left a comment

Choose a reason for hiding this comment

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

LGTM

@mikehalmamoj mikehalmamoj merged commit 234b785 into main Oct 31, 2024
2 checks passed
@mikehalmamoj mikehalmamoj deleted the mh-SDIT-2021-upsert-mappings branch October 31, 2024 10:28
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.

2 participants