diff --git a/prisma/migrations/20260621135734_add_case_model/migration.sql b/prisma/migrations/20260621135734_add_case_model/migration.sql new file mode 100644 index 0000000..8c590fc --- /dev/null +++ b/prisma/migrations/20260621135734_add_case_model/migration.sql @@ -0,0 +1,18 @@ +-- CreateTable "cases" +CREATE TABLE "cases" ( + "id" TEXT NOT NULL PRIMARY KEY, + "title" TEXT NOT NULL, + "ownerId" TEXT NOT NULL, + "status" TEXT NOT NULL DEFAULT 'open', + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL +); + +-- CreateIndex +CREATE INDEX "cases_ownerId_idx" ON "cases"("ownerId"); + +-- AddForeignKey for cases +ALTER TABLE "cases" ADD CONSTRAINT "cases_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey for investigation_notes +ALTER TABLE "investigation_notes" ADD CONSTRAINT "investigation_notes_caseId_fkey" FOREIGN KEY ("caseId") REFERENCES "cases"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml new file mode 100644 index 0000000..564d8c6 --- /dev/null +++ b/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added to your version control system (i.e. Git) +provider = "postgresql" diff --git a/prisma/schema.prisma b/prisma/schema.prisma index bbb931c..985264e 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -14,6 +14,7 @@ model User { watchlist Watchlist[] notificationPreferences NotificationPreference[] auditLogs AuditLog[] + cases Case[] @@map("users") } @@ -116,6 +117,25 @@ model GovernanceEvent { @@map("governance_events") } +// --------------------------------------------------------------------------- +// Case Management – independent investigation tracking +// --------------------------------------------------------------------------- + +model Case { + id String @id @default(cuid()) + title String + ownerId String + status String @default("open") // "open", "in_progress", "closed", "on_hold" + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + owner User @relation(fields: [ownerId], references: [id]) + investigationNotes InvestigationNote[] + + @@index([ownerId]) + @@map("cases") +} + // --------------------------------------------------------------------------- // Investigation Notes – issue #127 // --------------------------------------------------------------------------- @@ -133,7 +153,8 @@ model InvestigationNote { createdAt DateTime @default(now()) updatedAt DateTime @updatedAt - auditEntries NoteAuditLog[] + case Case @relation(fields: [caseId], references: [id], onDelete: Cascade) + auditEntries NoteAuditLog[] @@index([caseId]) @@map("investigation_notes")