Skip to content

Commit 5e75799

Browse files
authored
Merge pull request #530 from bcgov/chore/migrate-to-native-uuid
refactor: migrate to node:crypto UUIDv4 generation
2 parents 81c6081 + 41ebc94 commit 5e75799

28 files changed

Lines changed: 83 additions & 125 deletions

app/package-lock.json

Lines changed: 1 addition & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
"pg": "8.22.0",
8787
"proj4": "2.20.9",
8888
"tsx": "4.23.0",
89-
"uuid": "11.1.1",
9089
"winston-transport": "4.9.0"
9190
},
9291
"devDependencies": {

app/src/controllers/contact.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { v4 as uuidv4 } from 'uuid';
1+
import { randomUUID } from 'node:crypto';
22

33
import {
44
deleteContactService,
@@ -76,7 +76,7 @@ export const upsertContactController = async (
7676
req: Request<never, never, Contact, never>,
7777
res: Response<Contact, LocalContext>
7878
) => {
79-
const contact = { ...req.body, contactId: req.body.contactId ?? uuidv4() };
79+
const contact = { ...req.body, contactId: req.body.contactId ?? randomUUID() };
8080
const response = await upsertContactsService([contact]);
8181
res.status(200).json(response[0]);
8282
};

app/src/db/migrations/20231212000000_init.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
/* eslint-disable max-len */
2-
import { NIL, v4 as uuidv4 } from 'uuid';
2+
import { randomUUID } from 'node:crypto';
33

44
import { addAuditStamps } from '../utils/migrations/helpers.ts';
55

66
import type { Knex } from 'knex';
77

8+
const NIL_UUID = '00000000-0000-0000-0000-000000000000';
9+
810
export async function up(knex: Knex): Promise<void> {
911
return (
1012
Promise.resolve()
@@ -421,18 +423,18 @@ export async function up(knex: Knex): Promise<void> {
421423
.then(() => {
422424
const users = ['system'];
423425
const items = users.map((user) => ({
424-
user_id: NIL,
426+
user_id: NIL_UUID,
425427
username: user,
426428
active: true,
427-
created_by: NIL
429+
created_by: NIL_UUID
428430
}));
429431
return knex('user').insert(items);
430432
})
431433

432434
.then(() => {
433435
const items = [
434436
{
435-
initiative_id: uuidv4(),
437+
initiative_id: randomUUID(),
436438
code: 'HOUSING',
437439
label: 'Housing'
438440
}

app/src/db/migrations/20240904000000_009-rbac.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable max-len */
2-
import { v4 as uuidv4 } from 'uuid';
2+
import { randomUUID } from 'node:crypto';
33

44
import { addAuditStamps } from '../utils/migrations/helpers.ts';
55
import { Action, GroupName, Initiative, Resource, ResourceLegacy } from '../../utils/enums/application.ts';
@@ -420,7 +420,7 @@ export async function up(knex: Knex): Promise<void> {
420420
if (exists.length === 0) {
421421
const items = [
422422
{
423-
initiative_id: uuidv4(),
423+
initiative_id: randomUUID(),
424424
code: Initiative.PCNS,
425425
label: 'Permit Connect Navigator Service'
426426
}

app/src/db/migrations/20241125000000_014-user-contacts.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
/* eslint-disable max-len */
10-
import { v4 as uuidv4 } from 'uuid';
10+
import { randomUUID } from 'node:crypto';
1111

1212
import { addAuditStamps } from '../utils/migrations/helpers.ts';
1313

@@ -117,7 +117,7 @@ export async function up(knex: Knex): Promise<void> {
117117
.from({ s: 'public.submission' });
118118

119119
submissions = submissions.map((x) => ({
120-
contact_id: uuidv4(),
120+
contact_id: randomUUID(),
121121
...x
122122
}));
123123

@@ -134,7 +134,7 @@ export async function up(knex: Knex): Promise<void> {
134134
.from({ e: 'public.enquiry' });
135135

136136
enquiries = enquiries.map((x) => ({
137-
contact_id: uuidv4(),
137+
contact_id: randomUUID(),
138138
...x
139139
}));
140140

app/src/db/migrations/20250514000000_031-electrification.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable max-len */
2-
import { v4 as uuidv4 } from 'uuid';
2+
import { randomUUID } from 'node:crypto';
33

44
import { addAuditStamps } from '../utils/migrations/helpers.ts';
55
import { Action, GroupName, Initiative, Resource } from '../../utils/enums/application.ts';
@@ -186,7 +186,7 @@ export async function up(knex: Knex): Promise<void> {
186186
.then(() => {
187187
const items = [
188188
{
189-
initiative_id: uuidv4(),
189+
initiative_id: randomUUID(),
190190
code: 'ELECTRIFICATION',
191191
label: 'Electrification'
192192
}

app/src/db/migrations/20251027000000_044-system-id-change.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { NIL } from 'uuid';
2-
31
import { SYSTEM_ID } from '../../utils/constants/application.ts';
42

53
import type { Knex } from 'knex';
64

5+
const NIL_UUID = '00000000-0000-0000-0000-000000000000';
6+
77
export async function up(knex: Knex): Promise<void> {
88
return Promise.resolve()
99
.then(() => {
10-
return knex('user').where('user_id', NIL).update({ user_id: SYSTEM_ID });
10+
return knex('user').where('user_id', NIL_UUID).update({ user_id: SYSTEM_ID });
1111
})
1212

1313
.then(() =>
@@ -118,6 +118,6 @@ export async function down(knex: Knex): Promise<void> {
118118
)
119119

120120
.then(() => {
121-
return knex('user').where('user_id', SYSTEM_ID).update({ user_id: NIL });
121+
return knex('user').where('user_id', SYSTEM_ID).update({ user_id: NIL_UUID });
122122
});
123123
}

app/src/db/migrations/20260420000000_058-general-projects.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable max-len */
2-
import { v4 as uuidv4 } from 'uuid';
2+
import { randomUUID } from 'node:crypto';
33

44
import {
55
addAuditStamps,
@@ -35,7 +35,7 @@ export async function up(knex: Knex): Promise<void> {
3535
.then(() => {
3636
return knex('initiative').insert([
3737
{
38-
initiative_id: uuidv4(),
38+
initiative_id: randomUUID(),
3939
code: Initiative.GENERAL,
4040
label: 'Generic'
4141
}

app/src/domains/activity.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { v4 as uuidv4 } from 'uuid';
1+
import { randomUUID } from 'node:crypto';
22

33
import { Initiative } from '../utils/enums/application.ts';
44

@@ -19,7 +19,7 @@ export const createActivity = async (
1919
let id, queryResult;
2020

2121
do {
22-
id = uuidv4().substring(0, 8).toUpperCase();
22+
id = randomUUID().substring(0, 8).toUpperCase();
2323
queryResult = await repositories.activity.findUnique({
2424
where: { activityId: id },
2525
select: { activityId: true }

0 commit comments

Comments
 (0)