diff --git a/prisma/migrations/20261001081829_comment/migration.sql b/prisma/migrations/20261001081829_comment/migration.sql new file mode 100644 index 0000000..a0fc73a --- /dev/null +++ b/prisma/migrations/20261001081829_comment/migration.sql @@ -0,0 +1,25 @@ +-- CreateTable +CREATE TABLE "comment" ( + "id" TEXT NOT NULL, + "content" TEXT NOT NULL, + "issueId" INTEGER NOT NULL, + "authorId" TEXT, + "editedAt" TIMESTAMPTZ(3), + "deletedAt" TIMESTAMPTZ(3), + "createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMPTZ(3) NOT NULL, + + CONSTRAINT "comment_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE INDEX "comment_issueId_createdAt_idx" ON "comment"("issueId", "createdAt"); + +-- CreateIndex +CREATE INDEX "comment_authorId_idx" ON "comment"("authorId"); + +-- AddForeignKey +ALTER TABLE "comment" ADD CONSTRAINT "comment_issueId_fkey" FOREIGN KEY ("issueId") REFERENCES "issue"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "comment" ADD CONSTRAINT "comment_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "user"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 3b77c1f..d4e90f7 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -24,6 +24,7 @@ model User { notificationDeviceTokens NotificationDeviceToken[] notificationPreferences NotificationPreference[] notificationMessages NotificationMessage[] + comments Comment[] @@unique([email]) @@map("user") @@ -92,6 +93,7 @@ model Issue { projectId String project Project @relation(fields: [projectId], references: [id], onDelete: Cascade) dueDate DateTime? @db.Timestamptz(3) + comments Comment[] createdAt DateTime @default(now()) @db.Timestamptz(3) updatedAt DateTime @updatedAt @db.Timestamptz(3) @@ -188,3 +190,22 @@ model NotificationMessage { @@index([createdAt]) @@map("notification_message") } + +/// Комментарий к задаче. При удалении автора комментарий остаётся (authorId -> NULL). +/// deletedAt — мягкое удаление, editedAt — время последней правки текста. +model Comment { + id String @id @default(uuid(7)) + content String + issueId Int + issue Issue @relation(fields: [issueId], references: [id], onDelete: Cascade) + authorId String? + author User? @relation(fields: [authorId], references: [id], onDelete: SetNull) + editedAt DateTime? @db.Timestamptz(3) + deletedAt DateTime? @db.Timestamptz(3) + createdAt DateTime @default(now()) @db.Timestamptz(3) + updatedAt DateTime @updatedAt @db.Timestamptz(3) + + @@index([issueId, createdAt]) + @@index([authorId]) + @@map("comment") +}