Add personal/team note visibility and edit history.

Notes can be marked personal or team, with revision snapshots and restore from the notes UI.
This commit is contained in:
2026-09-27 13:19:08 +03:30
parent 55a287563d
commit 00f8b91d78
12 changed files with 655 additions and 22 deletions
@@ -0,0 +1,40 @@
-- AlterTable
ALTER TABLE "Note" ADD COLUMN "visibility" TEXT NOT NULL DEFAULT 'team';
-- CreateIndex
CREATE INDEX "Note_organizationId_visibility_idx" ON "Note"("organizationId", "visibility");
-- CreateTable
CREATE TABLE "NoteRevision" (
"id" TEXT NOT NULL,
"organizationId" TEXT NOT NULL,
"noteId" TEXT NOT NULL,
"editorId" TEXT,
"title" TEXT,
"body" TEXT NOT NULL,
"noteType" TEXT NOT NULL,
"visibility" TEXT NOT NULL DEFAULT 'team',
"tags" TEXT[] DEFAULT ARRAY[]::TEXT[],
"checklist" JSONB,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "NoteRevision_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "NoteRevision_noteId_createdAt_idx" ON "NoteRevision"("noteId", "createdAt");
-- CreateIndex
CREATE INDEX "NoteRevision_organizationId_idx" ON "NoteRevision"("organizationId");
-- CreateIndex
CREATE INDEX "NoteRevision_editorId_idx" ON "NoteRevision"("editorId");
-- AddForeignKey
ALTER TABLE "NoteRevision" ADD CONSTRAINT "NoteRevision_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "NoteRevision" ADD CONSTRAINT "NoteRevision_noteId_fkey" FOREIGN KEY ("noteId") REFERENCES "Note"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "NoteRevision" ADD CONSTRAINT "NoteRevision_editorId_fkey" FOREIGN KEY ("editorId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
+28
View File
@@ -162,6 +162,7 @@ model Organization {
deals Deal[]
activities Activity[]
notes Note[]
noteRevisions NoteRevision[]
customFields CustomFieldDefinition[]
products Product[]
notifications Notification[]
@@ -231,6 +232,7 @@ model User {
activities Activity[] @relation("ActivityAssignee")
createdActivities Activity[] @relation("ActivityCreator")
notes Note[] @relation("NoteAuthor")
noteRevisions NoteRevision[] @relation("NoteRevisionEditor")
noteAttachments NoteAttachment[] @relation("NoteAttachmentUploader")
notifications Notification[]
salesGoals SalesGoal[] @relation("SalesGoalUser")
@@ -591,14 +593,18 @@ model Note {
activity Activity? @relation(fields: [activityId], references: [id], onDelete: SetNull)
authorId String?
author User? @relation("NoteAuthor", fields: [authorId], references: [id], onDelete: SetNull)
/// team = قابل‌مشاهده برای تیم/سازمان در محدوده پرونده | personal = فقط نویسنده
visibility String @default("team")
attachments NoteAttachment[]
aiSuggestion NoteAiSuggestion?
revisions NoteRevision[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([organizationId, pinned, updatedAt])
@@index([organizationId, noteType, updatedAt])
@@index([organizationId, reminderAt])
@@index([organizationId, visibility])
@@index([personId])
@@index([companyId])
@@index([dealId])
@@ -606,6 +612,28 @@ model Note {
@@index([authorId])
}
/// اسنپ‌شات متن قبل از هر ویرایش معنادار یادداشت
model NoteRevision {
id String @id @default(cuid())
organizationId String
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
noteId String
note Note @relation(fields: [noteId], references: [id], onDelete: Cascade)
editorId String?
editor User? @relation("NoteRevisionEditor", fields: [editorId], references: [id], onDelete: SetNull)
title String?
body String
noteType String
visibility String @default("team")
tags String[] @default([])
checklist Json?
createdAt DateTime @default(now())
@@index([noteId, createdAt])
@@index([organizationId])
@@index([editorId])
}
model NoteAttachment {
id String @id @default(cuid())
organizationId String