Skip to content

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

feat: add prisma migrations

Marc Seitzc93637ded06e
diff --git a/prisma/migrations/20240327102407_add_dataroom/migration.sql b/prisma/migrations/20240327102407_add_dataroom/migration.sql
new file mode 100644
index 00000000..3a58676f
--- /dev/null
+++ b/prisma/migrations/20240327102407_add_dataroom/migration.sql
@@ -0,0 +1,91 @@
+-- CreateEnum
+CREATE TYPE "LinkType" AS ENUM ('DOCUMENT_LINK', 'DATAROOM_LINK');
+
+-- AlterTable
+ALTER TABLE "Link" ADD COLUMN "dataroomId" TEXT,
+ADD COLUMN "linkType" "LinkType" NOT NULL DEFAULT 'DOCUMENT_LINK',
+ALTER COLUMN "documentId" DROP NOT NULL;
+
+-- AlterTable
+ALTER TABLE "View" ADD COLUMN "dataroomId" TEXT,
+ADD COLUMN "dataroomViewId" TEXT,
+ALTER COLUMN "documentId" DROP NOT NULL;
+
+-- CreateTable
+CREATE TABLE "Dataroom" (
+ "id" TEXT NOT NULL,
+ "pId" TEXT NOT NULL,
+ "name" TEXT NOT NULL,
+ "teamId" TEXT NOT NULL,
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ "updatedAt" TIMESTAMP(3) NOT NULL,
+
+ CONSTRAINT "Dataroom_pkey" PRIMARY KEY ("id")
+);
+
+-- CreateTable
+CREATE TABLE "DataroomDocument" (
+ "id" TEXT NOT NULL,
+ "dataroomId" TEXT NOT NULL,
+ "documentId" TEXT NOT NULL,
+ "folderId" TEXT,
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ "updatedAt" TIMESTAMP(3) NOT NULL,
+
+ CONSTRAINT "DataroomDocument_pkey" PRIMARY KEY ("id")
+);
+
+-- CreateTable
+CREATE TABLE "DataroomFolder" (
+ "id" TEXT NOT NULL,
+ "name" TEXT NOT NULL,
+ "path" TEXT NOT NULL,
+ "parentId" TEXT,
+ "dataroomId" TEXT NOT NULL,
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ "updatedAt" TIMESTAMP(3) NOT NULL,
+
+ CONSTRAINT "DataroomFolder_pkey" PRIMARY KEY ("id")
+);
+
+-- CreateIndex
+CREATE UNIQUE INDEX "Dataroom_pId_key" ON "Dataroom"("pId");
+
+-- CreateIndex
+CREATE INDEX "Dataroom_teamId_idx" ON "Dataroom"("teamId");
+
+-- CreateIndex
+CREATE INDEX "DataroomDocument_folderId_idx" ON "DataroomDocument"("folderId");
+
+-- CreateIndex
+CREATE UNIQUE INDEX "DataroomDocument_dataroomId_documentId_key" ON "DataroomDocument"("dataroomId", "documentId");
+
+-- CreateIndex
+CREATE INDEX "DataroomFolder_parentId_idx" ON "DataroomFolder"("parentId");
+
+-- CreateIndex
+CREATE UNIQUE INDEX "DataroomFolder_dataroomId_path_key" ON "DataroomFolder"("dataroomId", "path");
+
+-- AddForeignKey
+ALTER TABLE "Link" ADD CONSTRAINT "Link_dataroomId_fkey" FOREIGN KEY ("dataroomId") REFERENCES "Dataroom"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "View" ADD CONSTRAINT "View_dataroomId_fkey" FOREIGN KEY ("dataroomId") REFERENCES "Dataroom"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Dataroom" ADD CONSTRAINT "Dataroom_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "DataroomDocument" ADD CONSTRAINT "DataroomDocument_dataroomId_fkey" FOREIGN KEY ("dataroomId") REFERENCES "Dataroom"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "DataroomDocument" ADD CONSTRAINT "DataroomDocument_documentId_fkey" FOREIGN KEY ("documentId") REFERENCES "Document"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "DataroomDocument" ADD CONSTRAINT "DataroomDocument_folderId_fkey" FOREIGN KEY ("folderId") REFERENCES "DataroomFolder"("id") ON DELETE SET NULL ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "DataroomFolder" ADD CONSTRAINT "DataroomFolder_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "DataroomFolder"("id") ON DELETE SET NULL ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "DataroomFolder" ADD CONSTRAINT "DataroomFolder_dataroomId_fkey" FOREIGN KEY ("dataroomId") REFERENCES "Dataroom"("id") ON DELETE CASCADE ON UPDATE CASCADE;
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 7dfab7c5..7ee45144 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -67,6 +67,7 @@ model Team {
invitations Invitation[]
sentEmails SentEmail[]
brand Brand?
+ datarooms Dataroom[]
plan String @default("free")
stripeId String? @unique // Stripe subscription / customer ID
@@ -138,6 +139,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
+
@@index([ownerId])
@@index([teamId])
@@index([folderId])
@@ -183,10 +186,18 @@ enum DocumentStorageType {
VERCEL_BLOB
}
+enum LinkType {
+ DOCUMENT_LINK
+ DATAROOM_LINK
+}
+
model Link {
id String @id @default(cuid())
- document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
- documentId String
+ 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)
url String? @unique
name String? // Link name
slug String? // Link slug for pretty URLs
@@ -235,16 +246,19 @@ model Domain {
}
model View {
- id String @id @default(cuid())
- link Link @relation(fields: [linkId], references: [id])
- linkId String
- document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
- documentId String
- viewerEmail String? // Email of the viewer if known
- verified Boolean @default(false) // Whether the viewer email has been verified
- viewedAt DateTime @default(now())
- downloadedAt DateTime? // This is the time the document was downloaded
- reactions Reaction[]
+ id String @id @default(cuid())
+ link Link @relation(fields: [linkId], references: [id])
+ linkId String
+ document Document? @relation(fields: [documentId], references: [id], onDelete: Cascade)
+ documentId String?
+ dataroom Dataroom? @relation(fields: [dataroomId], references: [id], onDelete: Cascade)
+ dataroomId String?
+ dataroomViewId String? // This is the view ID from the dataroom
+ viewerEmail String? // Email of the viewer if known
+ verified Boolean @default(false) // Whether the viewer email has been verified
+ viewedAt DateTime @default(now())
+ downloadedAt DateTime? // This is the time the document was downloaded
+ reactions Reaction[]
@@index([linkId])
@@index([documentId])
@@ -322,6 +336,57 @@ model Folder {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
- @@index([parentId])
@@unique([teamId, path])
+ @@index([parentId])
+}
+
+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[]
+
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+
+ @@index([teamId])
+}
+
+model DataroomDocument {
+ id String @id @default(cuid())
+ dataroomId String
+ dataroom Dataroom @relation(fields: [dataroomId], references: [id], onDelete: Cascade)
+ documentId String
+ document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
+ folderId String?
+ folder DataroomFolder? @relation(fields: [folderId], references: [id], onDelete: SetNull)
+
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+
+ @@unique([dataroomId, documentId])
+ @@index([folderId])
+}
+
+model DataroomFolder {
+ id String @id @default(cuid())
+ name String
+ path String // the materialized path to the folder; starts always with "/"
+ parentId String?
+ documents DataroomDocument[]
+ childFolders DataroomFolder[] @relation("SubFolders")
+ parentFolder DataroomFolder? @relation("SubFolders", fields: [parentId], references: [id], onDelete: SetNull)
+ dataroomId String
+ dataroom Dataroom @relation(fields: [dataroomId], references: [id], onDelete: Cascade)
+
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+
+ @@unique([dataroomId, path])
+ @@index([parentId])
}