Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat: add NotificationPreference and NotificationDigest prisma models

Cursor Agent0d3b4958c265
diff --git a/prisma/migrations/20260331000000_add_notification_preferences/migration.sql b/prisma/migrations/20260331000000_add_notification_preferences/migration.sql
new file mode 100644
index 00000000..70869b54
--- /dev/null
+++ b/prisma/migrations/20260331000000_add_notification_preferences/migration.sql
@@ -0,0 +1,43 @@
+-- CreateTable
+CREATE TABLE "NotificationPreference" (
+ "id" TEXT NOT NULL,
+ "userId" TEXT NOT NULL,
+ "teamId" TEXT NOT NULL,
+ "type" TEXT NOT NULL,
+ "frequency" TEXT NOT NULL DEFAULT 'IMMEDIATE',
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ "updatedAt" TIMESTAMP(3) NOT NULL,
+
+ CONSTRAINT "NotificationPreference_pkey" PRIMARY KEY ("id")
+);
+
+-- CreateTable
+CREATE TABLE "NotificationDigest" (
+ "id" TEXT NOT NULL,
+ "userId" TEXT NOT NULL,
+ "teamId" TEXT NOT NULL,
+ "type" TEXT NOT NULL,
+ "payload" JSONB NOT NULL,
+ "processedAt" TIMESTAMP(3),
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+
+ CONSTRAINT "NotificationDigest_pkey" PRIMARY KEY ("id")
+);
+
+-- CreateIndex
+CREATE UNIQUE INDEX "NotificationPreference_userId_teamId_type_key" ON "NotificationPreference"("userId", "teamId", "type");
+
+-- CreateIndex
+CREATE INDEX "NotificationPreference_userId_teamId_idx" ON "NotificationPreference"("userId", "teamId");
+
+-- CreateIndex
+CREATE INDEX "NotificationDigest_userId_teamId_type_processedAt_idx" ON "NotificationDigest"("userId", "teamId", "type", "processedAt");
+
+-- CreateIndex
+CREATE INDEX "NotificationDigest_createdAt_idx" ON "NotificationDigest"("createdAt");
+
+-- AddForeignKey
+ALTER TABLE "NotificationPreference" ADD CONSTRAINT "NotificationPreference_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "NotificationPreference" ADD CONSTRAINT "NotificationPreference_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;
diff --git a/prisma/schema/annotation.prisma b/prisma/schema/annotation.prisma
index 9a891b07..64937474 100644
--- a/prisma/schema/annotation.prisma
+++ b/prisma/schema/annotation.prisma
@@ -1,18 +1,18 @@
model DocumentAnnotation {
- id String @id @default(cuid())
- title String
- content Json // Rich text content stored as JSON (Tiptap/ProseMirror format)
- pages Int[] // Array of page numbers this annotation applies to
- documentId String
- document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
- teamId String
- team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
- createdById String
- createdBy User @relation(fields: [createdById], references: [id], onDelete: Cascade)
- isVisible Boolean @default(true) // Allow admin to hide/show annotations
- images AnnotationImage[] // Images attached to this annotation
- createdAt DateTime @default(now())
- updatedAt DateTime @updatedAt
+ id String @id @default(cuid())
+ title String
+ content Json // Rich text content stored as JSON (Tiptap/ProseMirror format)
+ pages Int[] // Array of page numbers this annotation applies to
+ documentId String
+ document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
+ teamId String
+ team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
+ createdById String
+ createdBy User @relation(fields: [createdById], references: [id], onDelete: Cascade)
+ isVisible Boolean @default(true) // Allow admin to hide/show annotations
+ images AnnotationImage[] // Images attached to this annotation
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
@@index([documentId])
@@index([teamId])
diff --git a/prisma/schema/dataroom.prisma b/prisma/schema/dataroom.prisma
index 44b1a869..9d118e94 100644
--- a/prisma/schema/dataroom.prisma
+++ b/prisma/schema/dataroom.prisma
@@ -2,7 +2,7 @@ model Dataroom {
id String @id @default(cuid())
pId String @unique // This is the generated public ID for the dataroom dr_1234
name String
- internalName String? // Private, internal name/alias visible only to the dataroom owner
+ internalName String? // Private, internal name/alias visible only to the dataroom owner
description String?
teamId String
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
@@ -48,7 +48,7 @@ model Dataroom {
// Introduction page settings
introductionEnabled Boolean @default(false) // Toggle to show introduction on first visit
- introductionContent Json? // TipTap JSON content for the introduction page
+ introductionContent Json? // TipTap JSON content for the introduction page
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@ -109,15 +109,15 @@ model DataroomFolder {
}
model DataroomBrand {
- id String @id @default(cuid())
- logo String? // This should be a reference to where the file is stored (S3, Google Cloud Storage, etc.)
- banner String? // This should be a reference to where the file is stored (S3, Google Cloud Storage, etc.)
- brandColor String? // This should be a reference to the brand color
- accentColor String? // This should be a reference to the accent color
- applyAccentColorToDataroomView Boolean @default(false) // When true, apply accentColor to dataroom list/tree viewer background
- welcomeMessage String? // This should be a reference to the welcome message
- dataroomId String @unique
- dataroom Dataroom @relation(fields: [dataroomId], references: [id], onDelete: Cascade)
+ id String @id @default(cuid())
+ logo String? // This should be a reference to where the file is stored (S3, Google Cloud Storage, etc.)
+ banner String? // This should be a reference to where the file is stored (S3, Google Cloud Storage, etc.)
+ brandColor String? // This should be a reference to the brand color
+ accentColor String? // This should be a reference to the accent color
+ applyAccentColorToDataroomView Boolean @default(false) // When true, apply accentColor to dataroom list/tree viewer background
+ welcomeMessage String? // This should be a reference to the welcome message
+ dataroomId String @unique
+ dataroom Dataroom @relation(fields: [dataroomId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
diff --git a/prisma/schema/document.prisma b/prisma/schema/document.prisma
index ed024596..813711eb 100644
--- a/prisma/schema/document.prisma
+++ b/prisma/schema/document.prisma
@@ -27,8 +27,8 @@ model Document {
folderId String? // Optional Folder ID for documents in folders
folder Folder? @relation(fields: [folderId], references: [id], onDelete: SetNull)
- datarooms DataroomDocument[] // Datarooms associated with this document
- tags TagItem[]
+ datarooms DataroomDocument[] // Datarooms associated with this document
+ tags TagItem[]
annotations DocumentAnnotation[] // Annotations for this document
// upload external documents
@@ -44,26 +44,26 @@ model Document {
}
model DocumentVersion {
- id String @id @default(cuid())
- versionNumber Int // e.g., 1, 2, 3 for version control
- document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
- documentId String
- file String // This should be a reference to where the file is stored (S3, Google Cloud Storage, etc.)
- originalFile String? // This should be a reference to the original file like pptx, xlsx, etc. (S3, Google Cloud Storage, etc.)
- type String? // This should be a reference to the file type (pdf, docx, etc.)
- contentType String? // This should be the actual contentType of the file like application/pdf, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, etc.
- fileSize BigInt? // This should be the size of the file in bytes
- storageType DocumentStorageType @default(VERCEL_BLOB)
- numPages Int? // This should be a reference to the number of pages in the document
- isPrimary Boolean @default(false) // Indicates if this is the primary version
- isVertical Boolean @default(false) // Indicates if the document is vertical (portrait) or not (landscape)
- fileId String? // This is the file ID of the OpenAI File API
+ id String @id @default(cuid())
+ versionNumber Int // e.g., 1, 2, 3 for version control
+ document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
+ documentId String
+ file String // This should be a reference to where the file is stored (S3, Google Cloud Storage, etc.)
+ originalFile String? // This should be a reference to the original file like pptx, xlsx, etc. (S3, Google Cloud Storage, etc.)
+ type String? // This should be a reference to the file type (pdf, docx, etc.)
+ contentType String? // This should be the actual contentType of the file like application/pdf, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, etc.
+ fileSize BigInt? // This should be the size of the file in bytes
+ storageType DocumentStorageType @default(VERCEL_BLOB)
+ numPages Int? // This should be a reference to the number of pages in the document
+ isPrimary Boolean @default(false) // Indicates if this is the primary version
+ isVertical Boolean @default(false) // Indicates if the document is vertical (portrait) or not (landscape)
+ fileId String? // This is the file ID of the OpenAI File API
vectorStoreFileId String? // OpenAI vector store file ID for AI search
- pages DocumentPage[]
- hasPages Boolean @default(false) // Indicates if the document has pages
- length Int? // This is the length of the video in seconds
- createdAt DateTime @default(now())
- updatedAt DateTime @updatedAt
+ pages DocumentPage[]
+ hasPages Boolean @default(false) // Indicates if the document has pages
+ length Int? // This is the length of the video in seconds
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
@@unique([versionNumber, documentId])
@@index([documentId])
diff --git a/prisma/schema/link.prisma b/prisma/schema/link.prisma
index 5e5858c5..2fb7bae1 100644
--- a/prisma/schema/link.prisma
+++ b/prisma/schema/link.prisma
@@ -93,7 +93,7 @@ model Link {
customFields CustomField[]
- tags TagItem[]
+ tags TagItem[]
viewerInvitations ViewerInvitation[]
// visitor groups for allow-list
@@ -175,7 +175,7 @@ model VisitorGroup {
emails String[] // List of emails and domains (e.g., "[email protected]", "@example.org")
teamId String
- team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
+ team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
links LinkVisitorGroup[]
diff --git a/prisma/schema/notification.prisma b/prisma/schema/notification.prisma
new file mode 100644
index 00000000..14775dbc
--- /dev/null
+++ b/prisma/schema/notification.prisma
@@ -0,0 +1,30 @@
+model NotificationPreference {
+ id String @id @default(cuid())
+ userId String
+ teamId String
+ type String // "DOCUMENT_VIEW" | "DATAROOM_VIEW" | "BLOCKED_ACCESS" | "DATAROOM_UPLOAD" | "CONVERSATION_MESSAGE"
+ frequency String @default("IMMEDIATE") // "IMMEDIATE" | "DAILY" | "WEEKLY" | "NEVER"
+
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
+ team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
+
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+
+ @@unique([userId, teamId, type])
+ @@index([userId, teamId])
+}
+
+model NotificationDigest {
+ id String @id @default(cuid())
+ userId String
+ teamId String
+ type String // same values as NotificationPreference.type
+ payload Json
+
+ processedAt DateTime?
+ createdAt DateTime @default(now())
+
+ @@index([userId, teamId, type, processedAt])
+ @@index([createdAt])
+}
diff --git a/prisma/schema/schema.prisma b/prisma/schema/schema.prisma
index ed667ed0..160fafee 100644
--- a/prisma/schema/schema.prisma
+++ b/prisma/schema/schema.prisma
@@ -64,24 +64,26 @@ model User {
messages Message[]
// FAQ system
- publishedFaqItems DataroomFaqItem[]
+ publishedFaqItems DataroomFaqItem[]
createdAnnotations DocumentAnnotation[] // Annotations created by this user
installedIntegrations InstalledIntegration[]
links Link[] @relation("LinkOwner")
+
+ notificationPreferences NotificationPreference[]
}
model Brand {
- id String @id @default(cuid())
- logo String? // This should be a reference to where the file is stored (S3, Google Cloud Storage, etc.)
- banner String? // Banner image for dataroom view (fallback)
- brandColor String? // This should be a reference to the brand color
- accentColor String? // This should be a reference to the accent color
+ id String @id @default(cuid())
+ logo String? // This should be a reference to where the file is stored (S3, Google Cloud Storage, etc.)
+ banner String? // Banner image for dataroom view (fallback)
+ brandColor String? // This should be a reference to the brand color
+ accentColor String? // This should be a reference to the accent color
applyAccentColorToDataroomView Boolean @default(false) // Global default for whether accentColor applies to dataroom list/tree viewer background
- welcomeMessage String? // This should be a reference to the welcome message
- teamId String @unique
- team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
+ welcomeMessage String? // This should be a reference to the welcome message
+ teamId String @unique
+ team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@ -104,7 +106,7 @@ model Domain {
Team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
verified Boolean @default(false) // Whether the domain has been verified
isDefault Boolean @default(false) // Whether the domain is the primary domain
- redirectUrl String? // URL to redirect to when visiting the root of this domain
+ redirectUrl String? // URL to redirect to when visiting the root of this domain
lastChecked DateTime @default(now())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@ -175,9 +177,9 @@ enum ViewType {
}
enum DownloadType {
- SINGLE // Individual document download
- BULK // Full dataroom bulk download
- FOLDER // Folder download
+ SINGLE // Individual document download
+ BULK // Full dataroom bulk download
+ FOLDER // Folder download
}
model Viewer {
@@ -256,8 +258,8 @@ model SentEmail {
}
model Chat {
- id String @id @default(cuid())
- title String? // Generated title from first message
+ id String @id @default(cuid())
+ title String? // Generated title from first message
// Context associations
teamId String
@@ -511,17 +513,17 @@ model TagItem {
}
model ViewerInvitation {
- id String @id @default(cuid())
+ id String @id @default(cuid())
viewerId String
- viewer Viewer @relation(fields: [viewerId], references: [id], onDelete: Cascade)
+ viewer Viewer @relation(fields: [viewerId], references: [id], onDelete: Cascade)
linkId String
- link Link @relation(fields: [linkId], references: [id], onDelete: Cascade)
+ link Link @relation(fields: [linkId], references: [id], onDelete: Cascade)
groupId String?
- group ViewerGroup? @relation(fields: [groupId], references: [id], onDelete: SetNull)
+ group ViewerGroup? @relation(fields: [groupId], references: [id], onDelete: SetNull)
invitedBy String
customMessage String?
- sentAt DateTime @default(now())
- status InvitationStatus @default(SENT)
+ sentAt DateTime @default(now())
+ status InvitationStatus @default(SENT)
createdAt DateTime @default(now())
diff --git a/prisma/schema/team.prisma b/prisma/schema/team.prisma
index 219eae85..7dbe9be3 100644
--- a/prisma/schema/team.prisma
+++ b/prisma/schema/team.prisma
@@ -1,16 +1,16 @@
model Team {
- id String @id @default(cuid())
- name String
- slug String? @unique // Optional human-readable identifier (e.g. "acme"), used for SSO login
- users UserTeam[]
- documents Document[]
- folders Folder[]
- domains Domain[]
- invitations Invitation[]
- sentEmails SentEmail[]
- brand Brand?
- datarooms Dataroom[]
- agreements Agreement[]
+ id String @id @default(cuid())
+ name String
+ slug String? @unique // Optional human-readable identifier (e.g. "acme"), used for SSO login
+ users UserTeam[]
+ documents Document[]
+ folders Folder[]
+ domains Domain[]
+ invitations Invitation[]
+ sentEmails SentEmail[]
+ brand Brand?
+ datarooms Dataroom[]
+ agreements Agreement[]
viewerGroups ViewerGroup[]
visitorGroups VisitorGroup[]
viewers Viewer[]
@@ -67,6 +67,8 @@ model Team {
ignoredDomains String[] // Domains that are ignored for the team
globalBlockList String[] // Email and domains that are blocked for the team
+
+ notificationPreferences NotificationPreference[]
}
enum Role {
diff --git a/prisma/schema/workflow.prisma b/prisma/schema/workflow.prisma
index a573787a..404f3063 100644
--- a/prisma/schema/workflow.prisma
+++ b/prisma/schema/workflow.prisma
@@ -22,8 +22,8 @@ model Workflow {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
- entryLink Link @relation(fields: [entryLinkId], references: [id], onDelete: Cascade)
- team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
+ entryLink Link @relation(fields: [entryLinkId], references: [id], onDelete: Cascade)
+ team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
steps WorkflowStep[]
executions WorkflowExecution[]
@@ -36,10 +36,10 @@ model WorkflowStep {
id String @id @default(cuid())
workflowId String
name String
- stepOrder Int // Execution order (priority-based routing)
+ stepOrder Int // Execution order (priority-based routing)
stepType WorkflowStepType @default(ROUTER)
- conditions Json // JSON array of conditions to evaluate
- actions Json // JSON array of actions to execute
+ conditions Json // JSON array of conditions to evaluate
+ actions Json // JSON array of actions to execute
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@ -58,8 +58,8 @@ model WorkflowExecution {
status ExecutionStatus
startedAt DateTime @default(now())
completedAt DateTime?
- result Json? // Final result/output (routing target)
- metadata Json? // Context data (referrer, user agent, etc.)
+ result Json? // Final result/output (routing target)
+ metadata Json? // Context data (referrer, user agent, etc.)
workflow Workflow @relation(fields: [workflowId], references: [id], onDelete: Cascade)
stepLogs WorkflowStepLog[]
@@ -70,14 +70,14 @@ model WorkflowExecution {
}
model WorkflowStepLog {
- id String @id @default(cuid())
+ id String @id @default(cuid())
executionId String
workflowStepId String
conditionsMatched Boolean
- conditionResults Json? // Which conditions passed/failed
- actionsExecuted Json? // Which actions ran
- executedAt DateTime @default(now())
- duration Int? // Execution time in ms
+ conditionResults Json? // Which conditions passed/failed
+ actionsExecuted Json? // Which actions ran
+ executedAt DateTime @default(now())
+ duration Int? // Execution time in ms
error String?
execution WorkflowExecution @relation(fields: [executionId], references: [id], onDelete: Cascade)
@@ -86,4 +86,3 @@ model WorkflowStepLog {
@@index([executionId])
@@index([workflowStepId])
}
-