refactor: migrate to native UUID - #530
Conversation
10cb9e6 to
e08bf38
Compare
e08bf38 to
cda0996
Compare
There was a problem hiding this comment.
Pull request overview
This PR migrates the backend from the external uuid package to Node.js native UUID generation (crypto.randomUUID()), and replaces uuid validation/version checks with custom utilities in app/src/utils/utils.ts.
Changes:
- Replaced
uuidv4()usage across services, domains, controllers, and migrations withrandomUUID(). - Reimplemented UUID v4 validation in
utils.uuidValidateV4()without theuuidpackage and updated unit tests accordingly. - Removed
uuidfromapp/package.jsondependencies and introducedNIL_UUIDconstant for migrations.
Reviewed changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| app/tests/unit/utils/utils.test.ts | Updates uuidValidateV4 tests to use real UUID strings instead of mocking uuid. |
| app/src/utils/utils.ts | Removes uuid dependency and adds regex-based UUID validation plus version extraction. |
| app/src/utils/constants/application.ts | Adds NIL_UUID constant for nil UUID usage in migrations. |
| app/src/services/roadmap.ts | Uses randomUUID() for noteHistoryId and noteId creation. |
| app/src/services/permit.ts | Uses randomUUID() when generating missing permitId. |
| app/src/services/noteHistory.ts | Uses randomUUID() for note/noteHistory ID creation. |
| app/src/services/login.ts | Uses randomUUID() for contactId on new contacts. |
| app/src/services/draft.ts | Uses randomUUID() for draftId. |
| app/src/services/accessRequest.ts | Uses randomUUID() for accessRequestId. |
| app/src/external/ches.ts | Uses randomUUID() for emailLogId generation. |
| app/src/domains/user.ts | Uses randomUUID() for userId generation. |
| app/src/domains/permit.ts | Uses randomUUID() for permitNoteId. |
| app/src/domains/housingProject.ts | Uses randomUUID() for generated IDs (permits + housingProjectId). |
| app/src/domains/generalProject.ts | Uses randomUUID() for generated IDs (permits + generalProjectId). |
| app/src/domains/enquiry.ts | Uses randomUUID() for enquiryId generation. |
| app/src/domains/electrificationProject.ts | Uses randomUUID() for electrification project UUID generation. |
| app/src/domains/activity.ts | Uses randomUUID() as the source for generated 8-char activityId. |
| app/src/db/migrations/20260420000000_058-general-projects.ts | Uses randomUUID() for inserted initiative_id. |
| app/src/db/migrations/20251027000000_044-system-id-change.ts | Replaces uuid.NIL usage with NIL_UUID. |
| app/src/db/migrations/20250514000000_031-electrification.ts | Uses randomUUID() for inserted initiative_id. |
| app/src/db/migrations/20241125000000_014-user-contacts.ts | Uses randomUUID() for generated contact_id during backfill. |
| app/src/db/migrations/20240904000000_009-rbac.ts | Uses randomUUID() for inserted initiative_id. |
| app/src/db/migrations/20231212000000_init.ts | Uses NIL_UUID for system user IDs and randomUUID() for inserted initiative_id. |
| app/src/controllers/contact.ts | Uses randomUUID() when contactId is absent. |
| app/package.json | Removes the uuid dependency from app dependencies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
966941d to
1d0c47d
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 25 out of 26 changed files in this pull request and generated 1 comment.
Files not reviewed (1)
- app/package-lock.json: Generated file
Comments suppressed due to low confidence (1)
app/package-lock.json:1648
- In package-lock.json, some platform-specific optional packages now have identical "os"/"cpu" constraints (e.g., both the -gnu and -musl variants are linux/x64) without any "libc" discriminator. This can cause npm to install multiple mutually-exclusive native bundles on Linux, increasing install size/time and potentially complicating native binary selection in build images. Consider regenerating the lockfile with the repository's standard Node/npm toolchain so that libc/platform metadata is preserved (or otherwise ensure platform-specific packages remain properly constrained).
1d0c47d to
cd7162f
Compare
|
|
||
| import type { Knex } from 'knex'; | ||
|
|
||
| const NIL_UUID = '00000000-0000-0000-0000-000000000000'; |
There was a problem hiding this comment.
This should probably be a app wide constant
There was a problem hiding this comment.
It's a holdover from when the system id was nil. We shouldn't be using nil elsewhere anymore.
Signed-off-by: Sanjay Babu <sanjaytkbabu@gmail.com>
…d of the uuid package Signed-off-by: Sanjay Babu <sanjaytkbabu@gmail.com>
Signed-off-by: Sanjay Babu <sanjaytkbabu@gmail.com>
cd7162f to
41ebc94
Compare
|
|





Description
This PR removes the external uuid package dependency and migrates to Node.js native UUID functionality using crypto.randomUUID() and custom validation utilities.
PADS-861
Types of changes
Checklist
Further comments