Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add schema for folders
Marc Seitzf892331dd8ff
diff --git a/prisma/migrations/20240313100203_add_folders/migration.sql b/prisma/migrations/20240313100203_add_folders/migration.sqlnew file mode 100644index 00000000..498b0e14--- /dev/null+++ b/prisma/migrations/20240313100203_add_folders/migration.sql@@ -0,0 +1,33 @@+-- AlterTable+ALTER TABLE "Document" ADD COLUMN "folderId" TEXT;++-- CreateTable+CREATE TABLE "Folder" (+ "id" TEXT NOT NULL,+ "name" TEXT NOT NULL,+ "path" TEXT NOT NULL,+ "parentId" TEXT,+ "teamId" TEXT NOT NULL,+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,+ "updatedAt" TIMESTAMP(3) NOT NULL,++ CONSTRAINT "Folder_pkey" PRIMARY KEY ("id")+);++-- CreateIndex+CREATE INDEX "Folder_parentId_idx" ON "Folder"("parentId");++-- CreateIndex+CREATE UNIQUE INDEX "Folder_teamId_path_key" ON "Folder"("teamId", "path");++-- CreateIndex+CREATE INDEX "Document_folderId_idx" ON "Document"("folderId");++-- AddForeignKey+ALTER TABLE "Document" ADD CONSTRAINT "Document_folderId_fkey" FOREIGN KEY ("folderId") REFERENCES "Folder"("id") ON DELETE SET NULL ON UPDATE CASCADE;++-- AddForeignKey+ALTER TABLE "Folder" ADD CONSTRAINT "Folder_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "Folder"("id") ON DELETE SET NULL ON UPDATE CASCADE;++-- AddForeignKey+ALTER TABLE "Folder" ADD CONSTRAINT "Folder_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex 9c60034e..7dfab7c5 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -58,21 +58,24 @@ model User {}model Team {- id String @id @default(cuid())- name String- users UserTeam[]- documents Document[]- domains Domain[]- invitations Invitation[]- sentEmails SentEmail[]- brand Brand?- plan String @default("free")- stripeId String? @unique // Stripe subscription / customer ID- subscriptionId String? @unique // Stripe subscription ID+ id String @id @default(cuid())+ name String+ users UserTeam[]+ documents Document[]+ folders Folder[]+ domains Domain[]+ invitations Invitation[]+ sentEmails SentEmail[]+ brand Brand?++ plan String @default("free")+ stripeId String? @unique // Stripe subscription / customer ID+ subscriptionId String? @unique // Stripe subscription IDstartsAt DateTime? // Stripe subscription start dateendsAt DateTime? // Stripe subscription end date- createdAt DateTime @default(now())- updatedAt DateTime @updatedAt++ createdAt DateTime @default(now())+ updatedAt DateTime @updatedAt}model Brand {@@ -132,8 +135,12 @@ model Document {versions DocumentVersion[]conversations Conversation[]+ folderId String? // Optional Folder ID for documents in folders+ folder Folder? @relation(fields: [folderId], references: [id], onDelete: SetNull)+@@index([ownerId])@@index([teamId])+ @@index([folderId])}model DocumentVersion {@@ -300,3 +307,21 @@ model Conversation {@@unique([threadId, documentId])@@index([threadId])}++model Folder {+ id String @id @default(cuid())+ name String+ path String // the materialized path to the folder; starts always with "/"+ parentId String?+ documents Document[]+ childFolders Folder[] @relation("SubFolders")+ parentFolder Folder? @relation("SubFolders", fields: [parentId], references: [id], onDelete: SetNull)+ teamId String+ team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)++ createdAt DateTime @default(now())+ updatedAt DateTime @updatedAt++ @@index([parentId])+ @@unique([teamId, path])+}