From 745a2e0c54f2a57349d637ae2229b5cd59285c1f Mon Sep 17 00:00:00 2001 From: trafficlunar Date: Fri, 23 May 2025 16:14:17 +0100 Subject: [PATCH] feat: add creatorId to report database schema should've been part of commit 36f0ff83 --- .../migration.sql | 5 +++++ prisma/schema.prisma | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 prisma/migrations/20250523141014_reports_target_creator/migration.sql diff --git a/prisma/migrations/20250523141014_reports_target_creator/migration.sql b/prisma/migrations/20250523141014_reports_target_creator/migration.sql new file mode 100644 index 0000000..b025e94 --- /dev/null +++ b/prisma/migrations/20250523141014_reports_target_creator/migration.sql @@ -0,0 +1,5 @@ +-- AlterTable +ALTER TABLE "reports" ADD COLUMN "creatorId" INTEGER; + +-- AddForeignKey +ALTER TABLE "reports" ADD CONSTRAINT "reports_creatorId_fkey" FOREIGN KEY ("creatorId") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 5f50162..fe62043 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -21,11 +21,12 @@ model User { usernameUpdatedAt DateTime? imageUpdatedAt DateTime? - accounts Account[] - sessions Session[] - miis Mii[] - likes Like[] - Report Report[] + accounts Account[] + sessions Session[] + miis Mii[] + likes Like[] + reportsAuthored Report[] @relation("ReportAuthor") + reports Report[] @relation("ReportTargetCreator") @@map("users") } @@ -106,11 +107,13 @@ model Report { reason ReportReason reasonNotes String? - // note: this refers to the person who made the report - authorId Int? createdAt DateTime @default(now()) - user User? @relation(fields: [authorId], references: [id]) + // note: this refers to the person who made the report + authorId Int? + author User? @relation("ReportAuthor", fields: [authorId], references: [id]) + creatorId Int? + creator User? @relation("ReportTargetCreator", fields: [creatorId], references: [id]) @@map("reports") }