From 9895cab5716035ec435c483f923216f7f0c7f306 Mon Sep 17 00:00:00 2001 From: codellins Date: Fri, 29 May 2026 15:51:30 +0100 Subject: [PATCH 1/7] fix(prisma): remove duplicate Dispute model blocking validation The schema defined Dispute twice, which prevents prisma validate from succeeding in local workspaces. Keep the enum-backed definition used by seed and repositories. Co-authored-by: Cursor --- prisma/schema.prisma | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index b9670bb1..f77a69bc 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -66,18 +66,6 @@ model Notification { escrow Escrow @relation(fields: [escrowId], references: [id], onDelete: Cascade) } -model Dispute { - id String @id @default(cuid()) - escrowId String @unique - reason String - status String @default("OPEN") - resolvedAt DateTime? - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - escrow Escrow @relation(fields: [escrowId], references: [id], onDelete: Cascade) -} - model VendorProfile { address String @id businessName String From 3ed4c6e454282d01fe5bfd5c4e44826b3aea5c5e Mon Sep 17 00:00:00 2001 From: codellins Date: Fri, 29 May 2026 15:51:33 +0100 Subject: [PATCH 2/7] feat(prisma): add EscrowEvent model for state-transition auditing Introduces an append-only EscrowEvent table mapping escrowId, optional fromState, toState, and createdAt for full lifecycle reconstruction. Co-authored-by: Cursor --- prisma/schema.prisma | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index f77a69bc..63e185cd 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -43,6 +43,20 @@ model Escrow { @@index([vendorAddress, state]) } +/// Append-only audit log of escrow state transitions (#108). +/// One row per state change captures previous and new state for lifecycle reconstruction. +model EscrowEvent { + id String @id @default(cuid()) + escrowId String + fromState String? + toState String + createdAt DateTime @default(now()) + + escrow Escrow @relation(fields: [escrowId], references: [id], onDelete: Cascade) + + @@index([escrowId]) +} + model Dispute { id String @id @default(uuid()) escrowId String From 95e458b1a2f8167d828cea3134b68d696e4bee78 Mon Sep 17 00:00:00 2001 From: codellins Date: Fri, 29 May 2026 15:51:36 +0100 Subject: [PATCH 3/7] feat(prisma): wire Escrow.events relation to EscrowEvent Connects the Escrow model to its append-only audit log so Prisma client queries can include event history via the ORM relation. Co-authored-by: Cursor --- prisma/schema.prisma | 1 + 1 file changed, 1 insertion(+) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 63e185cd..cdb1f450 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -37,6 +37,7 @@ model Escrow { updatedAt DateTime @updatedAt disputes Dispute[] notifications Notification[] + events EscrowEvent[] @@index([vendorAddress]) @@index([buyerAddress]) From 14300cbd07ba5141418cf25533fc936c24ce7158 Mon Sep 17 00:00:00 2001 From: codellins Date: Fri, 29 May 2026 15:51:38 +0100 Subject: [PATCH 4/7] chore(migration): scaffold add_escrow_event migration with audit header Adds the migration folder and documents the EscrowEvent auditing purpose before applying structural DDL changes. Co-authored-by: Cursor --- prisma/migrations/20260530100000_add_escrow_event/migration.sql | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 prisma/migrations/20260530100000_add_escrow_event/migration.sql diff --git a/prisma/migrations/20260530100000_add_escrow_event/migration.sql b/prisma/migrations/20260530100000_add_escrow_event/migration.sql new file mode 100644 index 00000000..3458c485 --- /dev/null +++ b/prisma/migrations/20260530100000_add_escrow_event/migration.sql @@ -0,0 +1,2 @@ +-- Issue #108: EscrowEvent table for append-only escrow state-transition auditing. +-- Supports reconstructing the full escrow lifecycle from persisted from/to states. From 2c6095cad62119406852fb1f7e2148ddd168f741 Mon Sep 17 00:00:00 2001 From: codellins Date: Fri, 29 May 2026 15:51:42 +0100 Subject: [PATCH 5/7] feat(migration): create EscrowEvent table for state-transition audit log Adds the EscrowEvent relation table with id, escrowId, fromState, toState, and createdAt columns matching the Prisma schema definition. Co-authored-by: Cursor --- .../20260530100000_add_escrow_event/migration.sql | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/prisma/migrations/20260530100000_add_escrow_event/migration.sql b/prisma/migrations/20260530100000_add_escrow_event/migration.sql index 3458c485..1dc37786 100644 --- a/prisma/migrations/20260530100000_add_escrow_event/migration.sql +++ b/prisma/migrations/20260530100000_add_escrow_event/migration.sql @@ -1,2 +1,13 @@ -- Issue #108: EscrowEvent table for append-only escrow state-transition auditing. -- Supports reconstructing the full escrow lifecycle from persisted from/to states. + +-- CreateTable +CREATE TABLE "EscrowEvent" ( + "id" TEXT NOT NULL, + "escrowId" TEXT NOT NULL, + "fromState" TEXT, + "toState" TEXT NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "EscrowEvent_pkey" PRIMARY KEY ("id") +); From ff9ff83cbd5b6d69a1db5ed2ad6d726d82243976 Mon Sep 17 00:00:00 2001 From: codellins Date: Fri, 29 May 2026 15:51:44 +0100 Subject: [PATCH 6/7] feat(migration): index EscrowEvent by escrowId and bind Escrow FK Adds escrowId lookup index and CASCADE foreign key so event rows are removed when parent escrows are deleted, matching the Prisma relation. Co-authored-by: Cursor --- .../20260530100000_add_escrow_event/migration.sql | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/prisma/migrations/20260530100000_add_escrow_event/migration.sql b/prisma/migrations/20260530100000_add_escrow_event/migration.sql index 1dc37786..e25aad3d 100644 --- a/prisma/migrations/20260530100000_add_escrow_event/migration.sql +++ b/prisma/migrations/20260530100000_add_escrow_event/migration.sql @@ -11,3 +11,9 @@ CREATE TABLE "EscrowEvent" ( CONSTRAINT "EscrowEvent_pkey" PRIMARY KEY ("id") ); + +-- CreateIndex +CREATE INDEX "EscrowEvent_escrowId_idx" ON "EscrowEvent"("escrowId"); + +-- AddForeignKey +ALTER TABLE "EscrowEvent" ADD CONSTRAINT "EscrowEvent_escrowId_fkey" FOREIGN KEY ("escrowId") REFERENCES "Escrow"("id") ON DELETE CASCADE ON UPDATE CASCADE; From 5d5bca78052a6dc6d115d211503cff71ea8fdfcf Mon Sep 17 00:00:00 2001 From: codellins Date: Fri, 29 May 2026 15:52:05 +0100 Subject: [PATCH 7/7] fix(prisma): drop orphaned VendorEscrows relation from VendorProfile Removes an Escrow back-relation that was never defined on Escrow, which blocked prisma validate from succeeding after the EscrowEvent schema work. Co-authored-by: Cursor --- prisma/schema.prisma | 1 - 1 file changed, 1 deletion(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index cdb1f450..9b577ec3 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -92,7 +92,6 @@ model VendorProfile { accountDetails VendorAccountDetails? trackingSettings VendorTrackingSettings? - escrows Escrow[] @relation("VendorEscrows") } model VendorAccountDetails {