feat: add document attachments feature

This commit is contained in:
Catalin Documenso
2025-04-25 13:49:22 +03:00
parent b94645a451
commit 1b67be9099
6 changed files with 190 additions and 4 deletions

View File

@ -0,0 +1,22 @@
-- CreateEnum
CREATE TYPE "AttachmentType" AS ENUM ('FILE', 'VIDEO', 'AUDIO', 'IMAGE', 'LINK', 'OTHER');
-- CreateTable
CREATE TABLE "Attachment" (
"id" TEXT NOT NULL,
"type" "AttachmentType" NOT NULL,
"label" TEXT NOT NULL,
"url" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"documentId" INTEGER,
"templateId" INTEGER,
CONSTRAINT "Attachment_pkey" PRIMARY KEY ("id")
);
-- AddForeignKey
ALTER TABLE "Attachment" ADD CONSTRAINT "Attachment_documentId_fkey" FOREIGN KEY ("documentId") REFERENCES "Document"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Attachment" ADD CONSTRAINT "Attachment_templateId_fkey" FOREIGN KEY ("templateId") REFERENCES "Template"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -312,6 +312,30 @@ enum DocumentVisibility {
ADMIN
}
enum AttachmentType {
FILE
VIDEO
AUDIO
IMAGE
LINK
OTHER
}
model Attachment {
id String @id @default(uuid())
type AttachmentType
label String
url String
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
documentId Int?
document Document? @relation(fields: [documentId], references: [id], onDelete: Cascade)
templateId Int?
template Template? @relation(fields: [templateId], references: [id], onDelete: Cascade)
}
/// @zod.import(["import { ZDocumentAuthOptionsSchema } from '@documenso/lib/types/document-auth';", "import { ZDocumentFormValuesSchema } from '@documenso/lib/types/document-form-values';"])
model Document {
id Int @id @default(autoincrement())
@ -339,7 +363,8 @@ model Document {
template Template? @relation(fields: [templateId], references: [id], onDelete: SetNull)
source DocumentSource
auditLogs DocumentAuditLog[]
auditLogs DocumentAuditLog[]
attachments Attachment[]
@@unique([documentDataId])
@@index([userId])
@ -713,6 +738,7 @@ model Template {
fields Field[]
directLink TemplateDirectLink?
documents Document[]
attachments Attachment[]
@@unique([templateDocumentDataId])
}