Skip to content

feat: migrate uuid v4 to v7 for chronologically sortable ids (#10378)#10935

Open
sh1vam31 wants to merge 6 commits intomedic:masterfrom
sh1vam31:10378-uuid-v7
Open

feat: migrate uuid v4 to v7 for chronologically sortable ids (#10378)#10935
sh1vam31 wants to merge 6 commits intomedic:masterfrom
sh1vam31:10378-uuid-v7

Conversation

@sh1vam31
Copy link
Copy Markdown
Contributor

Description

Fixes: #10378

This PR implements a project-wide migration from UUID v4 to UUID v7 as requested in issue #10378. Moving to v7 ensures that all generated IDs (contacts, reports, tasks, etc.) are time-prefixed and chronologically sortable, which will significantly improve B-tree indexing performance in CouchDB.

Changes:

Source Code Migration: Updated all instances of uuid.v4() to uuid.v7() (aliased as uuidv7() for clarity) in webapp, api, sentinel, and shared-libs.
API Enhancements: Modified api/src/routing.js to use UUID v7 for request IDs and increased shortUuid entropy from 12 to 16 characters to prevent collisions within the same millisecond.
Test Suite Updates: Performed a bulk update of all rosie factories and unit tests to align with the new UUID format.
Dependency Management: Standardized the use of the uuid package (v10+) and added @types/uuid to resolve TypeScript resolution issues in the webapp.
IDE & Linting: Fixed 100+ linting errors and shadowed variable issues introduced during the migration.
Verification Performed:

Verified chronological sortability of 100 generated IDs using a custom script.
Verified that all document IDs are explicitly assigned, maintaining compatibility with PouchDB's internal ID management.
Ran npm run lint project-wide (zero errors).
Verified core unit tests for api and webapp services.

Code review checklist

  • UI/UX backwards compatible: Test it works for the new design (enabled by default). And test it works in the old design, enable can_view_old_navigation permission to see the old design. Test it has appropriate design for RTL languages.
  • Readable: Concise, well named, follows the style guide
  • Documented: Configuration and user documentation on cht-docs
  • Tested: Unit and/or e2e where appropriate
  • Internationalised: All user facing text
  • Backwards compatible: Works with existing data and configuration or includes a migration. Any breaking changes documented in the release notes.
  • AI disclosure: Please disclose use of AI per the guidelines.

License

The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.

@sh1vam31
Copy link
Copy Markdown
Contributor Author

Hi @dianabarsan,

I have completed the migration from UUID v4 to UUID v7 across the codebase to enable chronologically sortable IDs for improved CouchDB performance.

Replaced uuid.v4 with uuid.v7 across the entire project (Source + Tests).
Verified chronological sortability of IDs for CouchDB performance.
Updated package-lock.json with necessary type definitions.

Kindly review this PR.

@sh1vam31 sh1vam31 changed the title feat: Migrate UUID v4 to v7 for chronologically sortable IDs (#10378) feat: migrate uuid v4 to v7 for chronologically sortable ids (#10378) Apr 26, 2026
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.

Switch to UUID v7 everywhere

1 participant