Skip to content

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

feat: add prisma migration

Marc Seitz18ecc3d811c2
diff --git a/prisma/migrations/20250413000000_add_dataroom_upload/migration.sql b/prisma/migrations/20250413000000_add_dataroom_upload/migration.sql
new file mode 100644
index 00000000..ba40d9d9
--- /dev/null
+++ b/prisma/migrations/20250413000000_add_dataroom_upload/migration.sql
@@ -0,0 +1,71 @@
+-- AlterTable
+ALTER TABLE "Document" ADD COLUMN "isExternalUpload" BOOLEAN NOT NULL DEFAULT false;
+
+-- AlterTable
+ALTER TABLE "Link" ADD COLUMN "enableUpload" BOOLEAN DEFAULT false,
+ADD COLUMN "isFileRequestOnly" BOOLEAN DEFAULT false,
+ADD COLUMN "uploadFolderId" TEXT;
+
+-- CreateTable
+CREATE TABLE "DocumentUpload" (
+ "id" TEXT NOT NULL,
+ "documentId" TEXT NOT NULL,
+ "teamId" TEXT NOT NULL,
+ "viewerId" TEXT,
+ "viewId" TEXT,
+ "linkId" TEXT NOT NULL,
+ "dataroomId" TEXT,
+ "dataroomDocumentId" TEXT,
+ "originalFilename" TEXT,
+ "fileSize" INTEGER,
+ "mimeType" TEXT,
+ "uploadedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ "updatedAt" TIMESTAMP(3) NOT NULL,
+ "numPages" INTEGER,
+
+ CONSTRAINT "DocumentUpload_pkey" PRIMARY KEY ("id")
+);
+
+-- CreateIndex
+CREATE INDEX "DocumentUpload_dataroomDocumentId_idx" ON "DocumentUpload"("dataroomDocumentId" ASC);
+
+-- CreateIndex
+CREATE INDEX "DocumentUpload_dataroomId_idx" ON "DocumentUpload"("dataroomId" ASC);
+
+-- CreateIndex
+CREATE INDEX "DocumentUpload_documentId_idx" ON "DocumentUpload"("documentId" ASC);
+
+-- CreateIndex
+CREATE INDEX "DocumentUpload_linkId_idx" ON "DocumentUpload"("linkId" ASC);
+
+-- CreateIndex
+CREATE INDEX "DocumentUpload_teamId_idx" ON "DocumentUpload"("teamId" ASC);
+
+-- CreateIndex
+CREATE INDEX "DocumentUpload_viewId_idx" ON "DocumentUpload"("viewId" ASC);
+
+-- CreateIndex
+CREATE INDEX "DocumentUpload_viewerId_idx" ON "DocumentUpload"("viewerId" ASC);
+
+-- AddForeignKey
+ALTER TABLE "DocumentUpload" ADD CONSTRAINT "DocumentUpload_dataroomDocumentId_fkey" FOREIGN KEY ("dataroomDocumentId") REFERENCES "DataroomDocument"("id") ON DELETE SET NULL ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "DocumentUpload" ADD CONSTRAINT "DocumentUpload_dataroomId_fkey" FOREIGN KEY ("dataroomId") REFERENCES "Dataroom"("id") ON DELETE SET NULL ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "DocumentUpload" ADD CONSTRAINT "DocumentUpload_documentId_fkey" FOREIGN KEY ("documentId") REFERENCES "Document"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "DocumentUpload" ADD CONSTRAINT "DocumentUpload_linkId_fkey" FOREIGN KEY ("linkId") REFERENCES "Link"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "DocumentUpload" ADD CONSTRAINT "DocumentUpload_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "DocumentUpload" ADD CONSTRAINT "DocumentUpload_viewId_fkey" FOREIGN KEY ("viewId") REFERENCES "View"("id") ON DELETE SET NULL ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "DocumentUpload" ADD CONSTRAINT "DocumentUpload_viewerId_fkey" FOREIGN KEY ("viewerId") REFERENCES "Viewer"("id") ON DELETE SET NULL ON UPDATE CASCADE;
+
diff --git a/prisma/schema/dataroom.prisma b/prisma/schema/dataroom.prisma
index 7f148c3a..2c5f1488 100644
--- a/prisma/schema/dataroom.prisma
+++ b/prisma/schema/dataroom.prisma
@@ -17,6 +17,9 @@ model Dataroom {
conversationsEnabled Boolean @default(false)
conversations Conversation[]
+ // upload external documents
+ uploadedDocuments DocumentUpload[]
+
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@ -35,6 +38,8 @@ model DataroomDocument {
conversations Conversation[]
+ uploadedDocuments DocumentUpload[]
+
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
diff --git a/prisma/schema/link.prisma b/prisma/schema/link.prisma
new file mode 100644
index 00000000..073ac88b
--- /dev/null
+++ b/prisma/schema/link.prisma
@@ -0,0 +1,136 @@
+enum LinkType {
+ DOCUMENT_LINK
+ DATAROOM_LINK
+}
+
+enum LinkAudienceType {
+ GENERAL
+ GROUP
+ TEAM
+}
+
+model Link {
+ id String @id @default(cuid())
+ document Document? @relation(fields: [documentId], references: [id], onDelete: Cascade)
+ documentId String? // This can be nullable, representing links without documents
+ dataroom Dataroom? @relation(fields: [dataroomId], references: [id], onDelete: Cascade)
+ dataroomId String? // This can be nullable, representing links without datarooms
+ linkType LinkType @default(DOCUMENT_LINK) // This will store the type of the link
+ url String? @unique
+ name String? // Link name
+ slug String? // Link slug for pretty URLs
+ expiresAt DateTime? // Optional expiration date
+ password String? // Optional password for link protection
+ allowList String[] // Array of emails and domains allowed to view the document
+ denyList String[] // Array of emails and domains denied to view the document
+ emailProtected Boolean @default(true) // Optional email protection
+ emailAuthenticated Boolean @default(false) // Optional email authentication flag
+ allowDownload Boolean? @default(false) // Optional give user a option to allow to download the document
+ isArchived Boolean @default(false) // Indicates if the link is archived
+ views View[]
+ domain Domain? @relation(fields: [domainId], references: [id], onDelete: SetNull)
+ domainId String? // This can be nullable, representing links without custom domains
+ domainSlug String? // This will store the domain's slug even if the domain is deleted
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+ enableNotification Boolean? @default(true) // Optional give user a option to pause/resume the notifications
+ enableFeedback Boolean? @default(false) // Optional give user a option to enable the reactions toolbar
+ enableQuestion Boolean? @default(false) // Optional give user a option to enable the question feedback
+ enableScreenshotProtection Boolean? @default(false) // Optional give user a option to enable the screenshot protection
+ feedback Feedback?
+ enableAgreement Boolean? @default(false) // Optional give user a option to enable the terms and conditions
+ agreement Agreement? @relation(fields: [agreementId], references: [id], onDelete: SetNull)
+ agreementId String? // This can be nullable, representing links without agreements
+ showBanner Boolean? @default(false) // Optional give user a option to show the banner and end of document signup form
+ enableWatermark Boolean? @default(false) // Optional give user a option to enable the watermark
+ watermarkConfig Json? // This will store the watermark configuration: {text: "Confidential", isTiled: false, color: "#000000", fontSize: 12, opacity: 0.5, rotation: 30, position: "top-right"}
+
+ // group links
+ audienceType LinkAudienceType @default(GENERAL) // This will store the audience type of the link
+ groupId String?
+ group ViewerGroup? @relation(fields: [groupId], references: [id], onDelete: SetNull)
+
+ // custom metatags
+ metaTitle String? // This will be the meta title of the link
+ metaDescription String? // This will be the meta description of the link
+ metaImage String? // This will be the meta image of the link
+ metaFavicon String? // This will be the meta favicon of the link
+ enableCustomMetatag Boolean? @default(false) // Optional give user a option to enable the custom metatag
+
+ // conversation
+ enableConversation Boolean @default(false) // Controls if conversations are allowed on this link
+ conversations Conversation[]
+
+ // upload
+ enableUpload Boolean? @default(false) // Optional give user a option to enable the upload document function
+ isFileRequestOnly Boolean? @default(false) // Optional give user a option to enable the file request only
+ uploadFolderId String? // This can be nullable, indicating upload to root folder, either document folder or dataroom folder
+
+ uploadedDocuments DocumentUpload[]
+
+ teamId String?
+ team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)
+
+ customFields CustomField[]
+
+ @@unique([domainSlug, slug])
+ @@index([documentId])
+ @@index([teamId])
+}
+
+model LinkPreset {
+ id String @id @default(cuid())
+ name String
+ teamId String
+ team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
+
+ enableCustomMetaTag Boolean? @default(false) // Optional give user a option to enable the custom metatag
+ metaTitle String? // This will be the meta title of the link
+ metaDescription String? // This will be the meta description of the link
+ metaImage String? // This will be the meta image of the link
+ metaFavicon String? // This will be the meta favicon of the link
+
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+
+ @@index([teamId])
+}
+
+enum CustomFieldType {
+ SHORT_TEXT
+ LONG_TEXT
+ NUMBER
+ PHONE_NUMBER
+ URL
+ CHECKBOX
+ SELECT
+ MULTI_SELECT
+}
+
+model CustomField {
+ id String @id @default(cuid())
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+ type CustomFieldType
+ identifier String
+ label String
+ placeholder String?
+ required Boolean @default(false)
+ disabled Boolean @default(false)
+ link Link @relation(fields: [linkId], references: [id], onDelete: Cascade)
+ linkId String
+ orderIndex Int @default(0)
+
+ @@index([linkId])
+}
+
+model CustomFieldResponse {
+ id String @id @default(cuid())
+ data Json // Store the custom field responses as a JSON object [{ "identifier": "value", "label": "value", "response:" }]
+ viewId String @unique
+ view View @relation(fields: [viewId], references: [id], onDelete: Cascade)
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+
+ @@index([viewId])
+}
\ No newline at end of file
diff --git a/prisma/schema/schema.prisma b/prisma/schema/schema.prisma
index a2ebc016..3f8e3e6f 100644
--- a/prisma/schema/schema.prisma
+++ b/prisma/schema/schema.prisma
@@ -98,6 +98,8 @@ model Team {
conversations Conversation[]
+ uploadedDocuments DocumentUpload[]
+
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
@@ -171,6 +173,10 @@ model Document {
datarooms DataroomDocument[] // Datarooms associated with this document
+ // upload external documents
+ uploadedDocument DocumentUpload[]
+ isExternalUpload Boolean @default(false) // Indicates if the document is an external upload
+
@@index([ownerId])
@@index([teamId])
@@index([folderId])
@@ -223,97 +229,6 @@ enum DocumentStorageType {
VERCEL_BLOB
}
-enum LinkType {
- DOCUMENT_LINK
- DATAROOM_LINK
-}
-
-enum LinkAudienceType {
- GENERAL
- GROUP
- TEAM
-}
-
-model Link {
- id String @id @default(cuid())
- document Document? @relation(fields: [documentId], references: [id], onDelete: Cascade)
- documentId String? // This can be nullable, representing links without documents
- dataroom Dataroom? @relation(fields: [dataroomId], references: [id], onDelete: Cascade)
- dataroomId String? // This can be nullable, representing links without datarooms
- linkType LinkType @default(DOCUMENT_LINK) // This will store the type of the link
- url String? @unique
- name String? // Link name
- slug String? // Link slug for pretty URLs
- expiresAt DateTime? // Optional expiration date
- password String? // Optional password for link protection
- allowList String[] // Array of emails and domains allowed to view the document
- denyList String[] // Array of emails and domains denied to view the document
- emailProtected Boolean @default(true) // Optional email protection
- emailAuthenticated Boolean @default(false) // Optional email authentication flag
- allowDownload Boolean? @default(false) // Optional give user a option to allow to download the document
- isArchived Boolean @default(false) // Indicates if the link is archived
- views View[]
- domain Domain? @relation(fields: [domainId], references: [id], onDelete: SetNull)
- domainId String? // This can be nullable, representing links without custom domains
- domainSlug String? // This will store the domain's slug even if the domain is deleted
- createdAt DateTime @default(now())
- updatedAt DateTime @updatedAt
- enableNotification Boolean? @default(true) // Optional give user a option to pause/resume the notifications
- enableFeedback Boolean? @default(false) // Optional give user a option to enable the reactions toolbar
- enableQuestion Boolean? @default(false) // Optional give user a option to enable the question feedback
- enableScreenshotProtection Boolean? @default(false) // Optional give user a option to enable the screenshot protection
- feedback Feedback?
- enableAgreement Boolean? @default(false) // Optional give user a option to enable the terms and conditions
- agreement Agreement? @relation(fields: [agreementId], references: [id], onDelete: SetNull)
- agreementId String? // This can be nullable, representing links without agreements
- showBanner Boolean? @default(false) // Optional give user a option to show the banner and end of document signup form
- enableWatermark Boolean? @default(false) // Optional give user a option to enable the watermark
- watermarkConfig Json? // This will store the watermark configuration: {text: "Confidential", isTiled: false, color: "#000000", fontSize: 12, opacity: 0.5, rotation: 30, position: "top-right"}
-
- // group links
- audienceType LinkAudienceType @default(GENERAL) // This will store the audience type of the link
- groupId String?
- group ViewerGroup? @relation(fields: [groupId], references: [id], onDelete: SetNull)
-
- // custom metatags
- metaTitle String? // This will be the meta title of the link
- metaDescription String? // This will be the meta description of the link
- metaImage String? // This will be the meta image of the link
- metaFavicon String? // This will be the meta favicon of the link
- enableCustomMetatag Boolean? @default(false) // Optional give user a option to enable the custom metatag
-
- // conversation
- enableConversation Boolean @default(false) // Controls if conversations are allowed on this link
- conversations Conversation[]
-
- teamId String?
- team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)
-
- customFields CustomField[]
-
- @@unique([domainSlug, slug])
- @@index([documentId])
- @@index([teamId])
-}
-
-model LinkPreset {
- id String @id @default(cuid())
- name String
- teamId String
- team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
-
- enableCustomMetaTag Boolean? @default(false) // Optional give user a option to enable the custom metatag
- metaTitle String? // This will be the meta title of the link
- metaDescription String? // This will be the meta description of the link
- metaImage String? // This will be the meta image of the link
- metaFavicon String? // This will be the meta favicon of the link
-
- createdAt DateTime @default(now())
- updatedAt DateTime @updatedAt
-
- @@index([teamId])
-}
-
model Domain {
id String @id @default(cuid())
slug String @unique
@@ -363,6 +278,8 @@ model View {
messages Message[]
initialConversations Conversation[] @relation("initialView")
+ uploadedDocuments DocumentUpload[] // uploaded documents by this view
+
teamId String?
team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)
@@ -395,6 +312,8 @@ model Viewer {
participatedConversations ConversationParticipant[]
messages Message[]
+ uploadedDocuments DocumentUpload[] // uploaded documents by this viewer
+
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@ -479,8 +398,6 @@ model Folder {
@@index([parentId])
}
-
-
model Feedback {
id String @id @default(cuid())
linkId String @unique
@@ -544,7 +461,6 @@ model AgreementResponse {
}
-
model IncomingWebhook {
id String @id @default(cuid())
externalId String @unique
@@ -621,41 +537,41 @@ model YearInReview {
@@index([teamId])
}
-enum CustomFieldType {
- SHORT_TEXT
- LONG_TEXT
- NUMBER
- PHONE_NUMBER
- URL
- CHECKBOX
- SELECT
- MULTI_SELECT
-}
-
-model CustomField {
- id String @id @default(cuid())
- createdAt DateTime @default(now())
- updatedAt DateTime @updatedAt
- type CustomFieldType
- identifier String
- label String
- placeholder String?
- required Boolean @default(false)
- disabled Boolean @default(false)
- link Link @relation(fields: [linkId], references: [id], onDelete: Cascade)
- linkId String
- orderIndex Int @default(0)
-
- @@index([linkId])
-}
-model CustomFieldResponse {
- id String @id @default(cuid())
- data Json // Store the custom field responses as a JSON object [{ "identifier": "value", "label": "value", "response:" }]
- viewId String @unique
- view View @relation(fields: [viewId], references: [id], onDelete: Cascade)
- createdAt DateTime @default(now())
- updatedAt DateTime @updatedAt
+model DocumentUpload {
+ id String @id @default(cuid())
+ documentId String
+ document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
+ teamId String
+ team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
+ viewerId String?
+ viewer Viewer? @relation(fields: [viewerId], references: [id], onDelete: SetNull)
+ viewId String?
+ view View? @relation(fields: [viewId], references: [id], onDelete: SetNull)
+ linkId String
+ link Link @relation(fields: [linkId], references: [id], onDelete: Cascade)
+
+ // Optional dataroom relations
+ dataroomId String?
+ dataroom Dataroom? @relation(fields: [dataroomId], references: [id], onDelete: SetNull)
+ dataroomDocumentId String?
+ dataroomDocument DataroomDocument? @relation(fields: [dataroomDocumentId], references: [id], onDelete: SetNull)
+
+ // Additional metadata
+ originalFilename String?
+ fileSize Int?
+ numPages Int?
+ mimeType String?
+ uploadedAt DateTime @default(now())
+
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+ @@index([documentId])
+ @@index([viewerId])
@@index([viewId])
+ @@index([linkId])
+ @@index([teamId])
+ @@index([dataroomId])
+ @@index([dataroomDocumentId])
}
\ No newline at end of file