From 105a82f97da8e3778751247f831f539ca4b65fc7 Mon Sep 17 00:00:00 2001 From: Hariom Balhara Date: Wed, 19 Nov 2025 18:47:02 +0530 Subject: [PATCH] feat: add uuidv7 and @db.Uuid to AuditActor and BookingAudit models (#25269) - Update AuditActor.id to use uuid(7) with @db.Uuid - Add @db.Uuid to BookingAudit.bookingUid and actorId fields - Create migration to convert existing TEXT columns to UUID type Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .../migration.sql | 20 +++++++++++++++++++ packages/prisma/schema.prisma | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 packages/prisma/migrations/20251119124132_add_uuidv7_to_audit_actor/migration.sql diff --git a/packages/prisma/migrations/20251119124132_add_uuidv7_to_audit_actor/migration.sql b/packages/prisma/migrations/20251119124132_add_uuidv7_to_audit_actor/migration.sql new file mode 100644 index 0000000000..7ed7084b8b --- /dev/null +++ b/packages/prisma/migrations/20251119124132_add_uuidv7_to_audit_actor/migration.sql @@ -0,0 +1,20 @@ +/* + Warnings: + + - The primary key for the `AuditActor` table will be changed. If it partially fails, the table could be left without primary key constraint. + - Changed the type of `id` on the `AuditActor` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. + - Changed the type of `actorId` on the `BookingAudit` table to UUID. + +*/ + +ALTER TABLE "public"."BookingAudit" DROP CONSTRAINT "BookingAudit_actorId_fkey"; + +ALTER TABLE "public"."BookingAudit" ALTER COLUMN "actorId" TYPE UUID USING "actorId"::UUID; + +ALTER TABLE "public"."AuditActor" DROP CONSTRAINT "AuditActor_pkey"; + +ALTER TABLE "public"."AuditActor" ALTER COLUMN "id" TYPE UUID USING "id"::UUID; + +ALTER TABLE "public"."AuditActor" ADD CONSTRAINT "AuditActor_pkey" PRIMARY KEY ("id"); + +ALTER TABLE "public"."BookingAudit" ADD CONSTRAINT "BookingAudit_actorId_fkey" FOREIGN KEY ("actorId") REFERENCES "public"."AuditActor"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/packages/prisma/schema.prisma b/packages/prisma/schema.prisma index 6b70715756..10908c67bf 100644 --- a/packages/prisma/schema.prisma +++ b/packages/prisma/schema.prisma @@ -2671,7 +2671,7 @@ enum AuditActorType { } model AuditActor { - id String @id @default(uuid()) + id String @id @default(uuid(7)) @db.Uuid type AuditActorType // References for different actor types (soft references, no FK constraints) @@ -2712,7 +2712,7 @@ model BookingAudit { // Actor who performed the action (USER, GUEST, or SYSTEM) // Stored in AuditActor table to maintain audit trail even after user deletion - actorId String + actorId String @db.Uuid // Restrict onDelete to prevent deletion of audit actor if there are any booking audits associated with it actor AuditActor @relation(fields: [actorId], references: [id], onDelete: Restrict)