Skip to content

make entities.uuid DB column of type uuid (rather than varchar(255))#1618

Merged
brontolosone merged 10 commits intogetodk:masterfrom
brontolosone:entities-uuid-be-uuid
Dec 5, 2025
Merged

make entities.uuid DB column of type uuid (rather than varchar(255))#1618
brontolosone merged 10 commits intogetodk:masterfrom
brontolosone:entities-uuid-be-uuid

Conversation

@brontolosone
Copy link
Contributor

@brontolosone brontolosone commented Sep 9, 2025

Following up on this Slack discussion.

What has been done to verify that this works as intended?

Tests, a few of which needed fixing, as they were supplying non-UUIDs as if they were UUIDs.

Why is this the best possible solution? Were any other approaches considered?

N/A

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

  • Users who get a sense of accomplishment out of disk space usage may be sad to see their DB disk space usage shrink and overall performance improved.
  • Users who somehow have succeeded in using non-UUID entity IDs (as the DB used to permit so), will be faced with an unmigratable DB. But on Slack I've been assured that this is not a likely scenario and that something must have gone very wrong to end up in that state.

Does this change require updates to the API documentation? If so, please update docs/api.yaml as part of this PR.

Not really.

Before submitting this PR, please make sure you have:

  • run make test and confirmed all checks still pass OR confirm CircleCI build passes
  • verified that any code from external sources are properly credited in comments or that everything is internally sourced

@brontolosone brontolosone requested review from alxndrsn and removed request for alxndrsn September 9, 2025 10:41
@github-project-automation github-project-automation bot moved this to 🕒 backlog in ODK Central Sep 10, 2025
@brontolosone brontolosone moved this from 🕒 backlog to ✏️ in progress in ODK Central Sep 10, 2025
@brontolosone brontolosone marked this pull request as ready for review September 10, 2025 12:18
@brontolosone brontolosone force-pushed the entities-uuid-be-uuid branch 3 times, most recently from 46169c4 to 20a68fd Compare September 11, 2025 06:34
@brontolosone brontolosone requested review from ktuite and sadiqkhoja and removed request for alxndrsn September 15, 2025 08:37
@matthew-white
Copy link
Member

@brontolosone, how's this PR looking in terms of status? I know you've been busy working on other things. I think it'd be nice to include this change in v2025.3, but to do so, we'll need to merge it within the next couple of days (before regression testing begins). From the comments above, it sounds like there are some small code changes to make.

@brontolosone
Copy link
Contributor Author

I'd thought it better to leave this one (and #1594) for the next cycle as I think they might be a bit of a distraction in light of the .3 release objectives. Plus it'd be nice to see improved benchmarks, but benchmarking infra is still in the works.

@matthew-white
Copy link
Member

Sounds good, I'll go ahead and remove it from v2025.3. 👍

@matthew-white matthew-white moved this from ✏️ in progress to 🕒 backlog in ODK Central Oct 21, 2025
@brontolosone brontolosone force-pushed the entities-uuid-be-uuid branch 2 times, most recently from 61769e6 to 39a552e Compare December 1, 2025 16:56
@brontolosone brontolosone force-pushed the entities-uuid-be-uuid branch from 39a552e to 814ff6a Compare December 1, 2025 19:23
@brontolosone brontolosone requested a review from ktuite December 1, 2025 19:28
@matthew-white matthew-white moved this from 🕒 backlog to ✏️ in progress in ODK Central Dec 1, 2025
@brontolosone brontolosone force-pushed the entities-uuid-be-uuid branch from 814ff6a to 0c0ddff Compare December 2, 2025 11:27
Copy link
Member

@ktuite ktuite left a comment

Choose a reason for hiding this comment

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

I'm happy with this!

See two fiddly comments about choice of uuid in tests for test clarity.

await asAlice.post('/v1/projects/1/datasets/people/entities/bulk-delete')
.send({
ids: ['12345678-1234-4123-8234-nonexistent']
ids: ['12345678-1234-4123-8234-0123456789ab']
Copy link
Member

Choose a reason for hiding this comment

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

With fresh eyes, I'd like to propose always using 00000000-0000-4000-8000-000000000000 in tests where the entity is not supposed to exist so it's clear and I don't have to remember which uuids the test fixtures are creating.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as in 915f5a5 ?

const asAlice = await service.login('alice');

await asAlice.post('/v1/projects/1/datasets/people/entities/12345678-1234-4123-8234-123456789abc/restore')
await asAlice.post('/v1/projects/1/datasets/people/entities/uuid:12345678-1234-4123-8234-123456789abc/restore')
Copy link
Member

Choose a reason for hiding this comment

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

So there are a couple new places entity uuid validation has been added/strengthened.

  1. normalizeUuid(wildtypeUuid) in Entities.getById (here) which covers situations like this, where a request was made with the uuid: prefix.

  2. Sanitize.queryParamToUuidArray in GeoExtracts.getEntityFeatureCollectionGeoJson (here) which reminds me of the situation above because it's about sanitizing query params, but isn't related because it actually for arrays of uuids specifically in the geo extraction code.

I didn't necessarily want a test of the restore endpoint to also test the uuid: prefix validation.

What if we remove the uuid: prefixes here in and in the next test, but leave the new test as is -- uuid:not-a-uuid seems fine for that situation.

And what if we add a more basic test like this near the top, say around line 265:

it('should strip uuid: prefix from query param in entity requests', testEntities(async (service) => {
  const asAlice = await service.login('alice');

  await asAlice.get('/v1/projects/1/datasets/people/entities/uuid:12345678-1234-4123-8234-123456789abc')
    .expect(200)
    .then(({ body }) => body.uuid.should.equal('12345678-1234-4123-8234-123456789abc'));
}));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@brontolosone brontolosone merged commit dc28c67 into getodk:master Dec 5, 2025
7 checks passed
brontolosone added a commit that referenced this pull request Dec 5, 2025
@github-project-automation github-project-automation bot moved this from ✏️ in progress to ✅ done in ODK Central Dec 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ done

Development

Successfully merging this pull request may close these issues.

4 participants