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)