Skip to content

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

feat: add group prisma migration

Marc Seitz950f0483e401
diff --git a/prisma/migrations/20240911000000_add_dataroom_groups_permissions/migration.sql b/prisma/migrations/20240911000000_add_dataroom_groups_permissions/migration.sql
new file mode 100644
index 00000000..57ab4838
--- /dev/null
+++ b/prisma/migrations/20240911000000_add_dataroom_groups_permissions/migration.sql
@@ -0,0 +1,101 @@
+-- CreateEnum
+CREATE TYPE "LinkAudienceType" AS ENUM ('GENERAL', 'GROUP', 'TEAM');
+
+-- CreateEnum
+CREATE TYPE "ItemType" AS ENUM ('DATAROOM_DOCUMENT', 'DATAROOM_FOLDER');
+
+-- AlterTable
+ALTER TABLE "Link" ADD COLUMN "audienceType" "LinkAudienceType" NOT NULL DEFAULT 'GENERAL',
+ADD COLUMN "groupId" TEXT;
+
+-- AlterTable
+ALTER TABLE "View" ADD COLUMN "groupId" TEXT;
+
+-- AlterTable
+ALTER TABLE "Viewer" ADD COLUMN "teamId" TEXT;
+
+-- CreateTable
+CREATE TABLE "ViewerGroup" (
+ "id" TEXT NOT NULL,
+ "name" TEXT NOT NULL,
+ "dataroomId" TEXT NOT NULL,
+ "teamId" TEXT NOT NULL,
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ "updatedAt" TIMESTAMP(3) NOT NULL,
+
+ CONSTRAINT "ViewerGroup_pkey" PRIMARY KEY ("id")
+);
+
+-- CreateTable
+CREATE TABLE "ViewerGroupMembership" (
+ "id" TEXT NOT NULL,
+ "viewerId" TEXT NOT NULL,
+ "groupId" TEXT NOT NULL,
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ "updatedAt" TIMESTAMP(3) NOT NULL,
+
+ CONSTRAINT "ViewerGroupMembership_pkey" PRIMARY KEY ("id")
+);
+
+-- CreateTable
+CREATE TABLE "ViewerGroupAccessControls" (
+ "id" TEXT NOT NULL,
+ "groupId" TEXT NOT NULL,
+ "itemId" TEXT NOT NULL,
+ "itemType" "ItemType" NOT NULL,
+ "canView" BOOLEAN NOT NULL DEFAULT true,
+ "canDownload" BOOLEAN NOT NULL DEFAULT false,
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ "updatedAt" TIMESTAMP(3) NOT NULL,
+
+ CONSTRAINT "ViewerGroupAccessControls_pkey" PRIMARY KEY ("id")
+);
+
+-- CreateIndex
+CREATE INDEX "ViewerGroup_dataroomId_idx" ON "ViewerGroup"("dataroomId");
+
+-- CreateIndex
+CREATE INDEX "ViewerGroup_teamId_idx" ON "ViewerGroup"("teamId");
+
+-- CreateIndex
+CREATE INDEX "ViewerGroupMembership_viewerId_idx" ON "ViewerGroupMembership"("viewerId");
+
+-- CreateIndex
+CREATE INDEX "ViewerGroupMembership_groupId_idx" ON "ViewerGroupMembership"("groupId");
+
+-- CreateIndex
+CREATE UNIQUE INDEX "ViewerGroupMembership_viewerId_groupId_key" ON "ViewerGroupMembership"("viewerId", "groupId");
+
+-- CreateIndex
+CREATE INDEX "ViewerGroupAccessControls_groupId_idx" ON "ViewerGroupAccessControls"("groupId");
+
+-- CreateIndex
+CREATE UNIQUE INDEX "ViewerGroupAccessControls_groupId_itemId_key" ON "ViewerGroupAccessControls"("groupId", "itemId");
+
+-- CreateIndex
+CREATE INDEX "Viewer_teamId_idx" ON "Viewer"("teamId");
+
+-- AddForeignKey
+ALTER TABLE "Link" ADD CONSTRAINT "Link_groupId_fkey" FOREIGN KEY ("groupId") REFERENCES "ViewerGroup"("id") ON DELETE SET NULL ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "View" ADD CONSTRAINT "View_groupId_fkey" FOREIGN KEY ("groupId") REFERENCES "ViewerGroup"("id") ON DELETE SET NULL ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Viewer" ADD CONSTRAINT "Viewer_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "ViewerGroup" ADD CONSTRAINT "ViewerGroup_dataroomId_fkey" FOREIGN KEY ("dataroomId") REFERENCES "Dataroom"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "ViewerGroup" ADD CONSTRAINT "ViewerGroup_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "ViewerGroupMembership" ADD CONSTRAINT "ViewerGroupMembership_viewerId_fkey" FOREIGN KEY ("viewerId") REFERENCES "Viewer"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "ViewerGroupMembership" ADD CONSTRAINT "ViewerGroupMembership_groupId_fkey" FOREIGN KEY ("groupId") REFERENCES "ViewerGroup"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "ViewerGroupAccessControls" ADD CONSTRAINT "ViewerGroupAccessControls_groupId_fkey" FOREIGN KEY ("groupId") REFERENCES "ViewerGroup"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 71f872bf..a86b5e94 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -58,17 +58,19 @@ model User {
}
model Team {
- id String @id @default(cuid())
- name String
- 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
+ users UserTeam[]
+ documents Document[]
+ folders Folder[]
+ domains Domain[]
+ invitations Invitation[]
+ sentEmails SentEmail[]
+ brand Brand?
+ datarooms Dataroom[]
+ agreements Agreement[]
+ viewerGroups ViewerGroup[]
+ viewers Viewer[]
plan String @default("free")
stripeId String? @unique // Stripe customer ID
@@ -200,13 +202,19 @@ enum LinkType {
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)
+ 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
@@ -234,7 +242,12 @@ model Link {
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"}
+ 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
@@ -247,11 +260,11 @@ model Link {
}
model LinkPreset {
- id String @id @default(cuid())
- name String
- teamId String
- team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
-
+ 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
@@ -299,6 +312,8 @@ model View {
viewType ViewType @default(DOCUMENT_VIEW)
viewerId String? // This is the viewer ID from the dataroom
viewer Viewer? @relation(fields: [viewerId], references: [id], onDelete: Cascade)
+ groupId String? // This is the group ID from the dataroom
+ group ViewerGroup? @relation(fields: [groupId], references: [id], onDelete: SetNull)
feedbackResponse FeedbackResponse?
agreementResponse AgreementResponse?
@@ -321,12 +336,17 @@ model Viewer {
dataroomId String
dataroom Dataroom @relation(fields: [dataroomId], references: [id], onDelete: Cascade)
- views View[]
+ teamId String?
+ team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)
+
+ views View[]
+ groups ViewerGroupMembership[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([dataroomId, email])
+ @@index([teamId])
@@index([dataroomId])
}
@@ -407,17 +427,18 @@ model Folder {
}
model Dataroom {
- id String @id @default(cuid())
- pId String @unique // This is the generated public ID for the dataroom dr_1234
- name String
- teamId String
- team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
- documents DataroomDocument[]
- folders DataroomFolder[]
- links Link[]
- views View[]
- viewers Viewer[]
- brand DataroomBrand?
+ id String @id @default(cuid())
+ pId String @unique // This is the generated public ID for the dataroom dr_1234
+ name String
+ teamId String
+ team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
+ documents DataroomDocument[]
+ folders DataroomFolder[]
+ links Link[]
+ views View[]
+ viewers Viewer[]
+ viewerGroups ViewerGroup[]
+ brand DataroomBrand?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@ -433,7 +454,7 @@ model DataroomDocument {
document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
folderId String?
folder DataroomFolder? @relation(fields: [folderId], references: [id], onDelete: SetNull)
- orderIndex Int?
+ orderIndex Int?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@ -453,7 +474,7 @@ model DataroomFolder {
parentFolder DataroomFolder? @relation("SubFolders", fields: [parentId], references: [id], onDelete: SetNull)
dataroomId String
dataroom Dataroom @relation(fields: [dataroomId], references: [id], onDelete: Cascade)
- orderIndex Int?
+ orderIndex Int?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@ -513,7 +534,7 @@ model Agreement {
links Link[]
responses AgreementResponse[]
- requireName Boolean @default(true) // Optional require name field
+ requireName Boolean @default(true) // Optional require name field
teamId String
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
@@ -537,3 +558,64 @@ model AgreementResponse {
@@index([agreementId])
@@index([viewId])
}
+
+model ViewerGroup {
+ id String @id @default(cuid())
+ name String
+ members ViewerGroupMembership[]
+ links Link[]
+ accessControls ViewerGroupAccessControls[]
+
+ dataroomId String
+ dataroom Dataroom @relation(fields: [dataroomId], references: [id], onDelete: Cascade)
+ teamId String
+ team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
+
+ views View[]
+
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+
+ @@index([dataroomId])
+ @@index([teamId])
+}
+
+model ViewerGroupMembership {
+ id String @id @default(cuid())
+ viewerId String
+ viewer Viewer @relation(fields: [viewerId], references: [id], onDelete: Cascade)
+ groupId String
+ group ViewerGroup @relation(fields: [groupId], references: [id], onDelete: Cascade)
+
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+
+ @@unique([viewerId, groupId])
+ @@index([viewerId])
+ @@index([groupId])
+}
+
+model ViewerGroupAccessControls {
+ id String @id @default(cuid())
+ groupId String
+ group ViewerGroup @relation(fields: [groupId], references: [id], onDelete: Cascade)
+
+ // Access control for items (documents or dataroom items)
+ itemId String // This can be a document ID or a dataroom item ID
+ itemType ItemType // Enum: DATAROOM_DOCUMENT, DATAROOM_FOLDER
+
+ // Granular permissions
+ canView Boolean @default(true)
+ canDownload Boolean @default(false)
+
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+
+ @@unique([groupId, itemId])
+ @@index([groupId])
+}
+
+enum ItemType {
+ DATAROOM_DOCUMENT
+ DATAROOM_FOLDER
+}