mirror of
https://github.com/documenso/documenso.git
synced 2025-11-20 19:51:32 +10:00
fix: wip
This commit is contained in:
261
packages/prisma/migrations/20250822050636_asdfasdf/migration.sql
Normal file
261
packages/prisma/migrations/20250822050636_asdfasdf/migration.sql
Normal file
@ -0,0 +1,261 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `authOptions` on the `Document` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `completedAt` on the `Document` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `createdAt` on the `Document` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `deletedAt` on the `Document` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `externalId` on the `Document` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `folderId` on the `Document` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `formValues` on the `Document` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `source` on the `Document` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `status` on the `Document` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `teamId` on the `Document` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `templateId` on the `Document` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `updatedAt` on the `Document` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `useLegacyFieldInsertion` on the `Document` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `userId` on the `Document` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `visibility` on the `Document` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `documentId` on the `DocumentAuditLog` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `documentId` on the `DocumentMeta` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `templateId` on the `DocumentMeta` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `documentId` on the `DocumentShareLink` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `documentId` on the `Field` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `templateId` on the `Field` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `documentId` on the `Recipient` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `templateId` on the `Recipient` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `templateId` on the `TemplateDirectLink` table. All the data in the column will be lost.
|
||||
- You are about to drop the `Template` table. If the table is not empty, all the data it contains will be lost.
|
||||
- A unique constraint covering the columns `[envelopeId,email]` on the table `DocumentShareLink` will be added. If there are existing duplicate values, this will fail.
|
||||
- A unique constraint covering the columns `[envelopeId,email]` on the table `Recipient` will be added. If there are existing duplicate values, this will fail.
|
||||
- A unique constraint covering the columns `[envelopeId]` on the table `TemplateDirectLink` will be added. If there are existing duplicate values, this will fail.
|
||||
- Added the required column `envelopeId` to the `DocumentAuditLog` table without a default value. This is not possible if the table is not empty.
|
||||
- Added the required column `envelopeId` to the `DocumentShareLink` table without a default value. This is not possible if the table is not empty.
|
||||
- Added the required column `envelopeId` to the `Field` table without a default value. This is not possible if the table is not empty.
|
||||
- Added the required column `envelopeId` to the `Recipient` table without a default value. This is not possible if the table is not empty.
|
||||
- Added the required column `envelopeId` to the `TemplateDirectLink` table without a default value. This is not possible if the table is not empty.
|
||||
- Added the required column `type` to the `TemplateDirectLink` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- CreateEnum
|
||||
CREATE TYPE "EnvelopeType" AS ENUM ('DOCUMENT', 'TEMPLATE');
|
||||
|
||||
-- CreateEnum
|
||||
CREATE TYPE "TemplateDirectLinkType" AS ENUM ('PUBLIC', 'PRIVATE');
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Document" DROP CONSTRAINT "Document_folderId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Document" DROP CONSTRAINT "Document_teamId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Document" DROP CONSTRAINT "Document_templateId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Document" DROP CONSTRAINT "Document_userId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "DocumentAuditLog" DROP CONSTRAINT "DocumentAuditLog_documentId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "DocumentMeta" DROP CONSTRAINT "DocumentMeta_documentId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "DocumentMeta" DROP CONSTRAINT "DocumentMeta_templateId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "DocumentShareLink" DROP CONSTRAINT "DocumentShareLink_documentId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Field" DROP CONSTRAINT "Field_documentId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Field" DROP CONSTRAINT "Field_templateId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Recipient" DROP CONSTRAINT "Recipient_documentId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Recipient" DROP CONSTRAINT "Recipient_templateId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Template" DROP CONSTRAINT "Template_folderId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Template" DROP CONSTRAINT "Template_teamId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Template" DROP CONSTRAINT "Template_templateDocumentDataId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Template" DROP CONSTRAINT "Template_userId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "TemplateDirectLink" DROP CONSTRAINT "TemplateDirectLink_templateId_fkey";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "Document_folderId_idx";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "Document_status_idx";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "Document_userId_idx";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "DocumentMeta_documentId_key";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "DocumentMeta_templateId_key";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "DocumentShareLink_documentId_email_key";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "Field_documentId_idx";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "Field_templateId_idx";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "Recipient_documentId_email_key";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "Recipient_documentId_idx";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "Recipient_templateId_email_key";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "Recipient_templateId_idx";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "TemplateDirectLink_templateId_key";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Document" DROP COLUMN "authOptions",
|
||||
DROP COLUMN "completedAt",
|
||||
DROP COLUMN "createdAt",
|
||||
DROP COLUMN "deletedAt",
|
||||
DROP COLUMN "externalId",
|
||||
DROP COLUMN "folderId",
|
||||
DROP COLUMN "formValues",
|
||||
DROP COLUMN "source",
|
||||
DROP COLUMN "status",
|
||||
DROP COLUMN "teamId",
|
||||
DROP COLUMN "templateId",
|
||||
DROP COLUMN "updatedAt",
|
||||
DROP COLUMN "useLegacyFieldInsertion",
|
||||
DROP COLUMN "userId",
|
||||
DROP COLUMN "visibility";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "DocumentAuditLog" DROP COLUMN "documentId",
|
||||
ADD COLUMN "envelopeId" TEXT NOT NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "DocumentMeta" DROP COLUMN "documentId",
|
||||
DROP COLUMN "templateId",
|
||||
ADD COLUMN "envelopeId" TEXT;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "DocumentShareLink" DROP COLUMN "documentId",
|
||||
ADD COLUMN "envelopeId" TEXT NOT NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Field" DROP COLUMN "documentId",
|
||||
DROP COLUMN "templateId",
|
||||
ADD COLUMN "envelopeId" TEXT NOT NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Recipient" DROP COLUMN "documentId",
|
||||
DROP COLUMN "templateId",
|
||||
ADD COLUMN "envelopeId" TEXT NOT NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "TemplateDirectLink" DROP COLUMN "templateId",
|
||||
ADD COLUMN "envelopeId" TEXT NOT NULL,
|
||||
ADD COLUMN "type" "TemplateDirectLinkType" NOT NULL;
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "Template";
|
||||
|
||||
-- DropEnum
|
||||
DROP TYPE "TemplateType";
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Envelope" (
|
||||
"id" TEXT NOT NULL,
|
||||
"secondaryId" TEXT NOT NULL,
|
||||
"externalId" TEXT,
|
||||
"type" "EnvelopeType" NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
"completedAt" TIMESTAMP(3),
|
||||
"deletedAt" TIMESTAMP(3),
|
||||
"title" TEXT NOT NULL,
|
||||
"status" "DocumentStatus" NOT NULL DEFAULT 'DRAFT',
|
||||
"source" "DocumentSource" NOT NULL,
|
||||
"useLegacyFieldInsertion" BOOLEAN NOT NULL DEFAULT false,
|
||||
"authOptions" JSONB,
|
||||
"formValues" JSONB,
|
||||
"visibility" "DocumentVisibility" NOT NULL DEFAULT 'EVERYONE',
|
||||
"publicTitle" TEXT NOT NULL DEFAULT '',
|
||||
"publicDescription" TEXT NOT NULL DEFAULT '',
|
||||
"templateId" INTEGER,
|
||||
"userId" INTEGER NOT NULL,
|
||||
"teamId" INTEGER NOT NULL,
|
||||
"folderId" TEXT,
|
||||
"documentMetaId" TEXT NOT NULL,
|
||||
|
||||
CONSTRAINT "Envelope_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Envelope_secondaryId_key" ON "Envelope"("secondaryId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Envelope_documentMetaId_key" ON "Envelope"("documentMetaId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "DocumentShareLink_envelopeId_email_key" ON "DocumentShareLink"("envelopeId", "email");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Field_envelopeId_idx" ON "Field"("envelopeId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Recipient_envelopeId_idx" ON "Recipient"("envelopeId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Recipient_envelopeId_email_key" ON "Recipient"("envelopeId", "email");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "TemplateDirectLink_envelopeId_key" ON "TemplateDirectLink"("envelopeId");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Envelope" ADD CONSTRAINT "Envelope_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Envelope" ADD CONSTRAINT "Envelope_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Envelope" ADD CONSTRAINT "Envelope_folderId_fkey" FOREIGN KEY ("folderId") REFERENCES "Folder"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Envelope" ADD CONSTRAINT "Envelope_documentMetaId_fkey" FOREIGN KEY ("documentMetaId") REFERENCES "DocumentMeta"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "DocumentAuditLog" ADD CONSTRAINT "DocumentAuditLog_envelopeId_fkey" FOREIGN KEY ("envelopeId") REFERENCES "Envelope"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Recipient" ADD CONSTRAINT "Recipient_envelopeId_fkey" FOREIGN KEY ("envelopeId") REFERENCES "Envelope"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Field" ADD CONSTRAINT "Field_envelopeId_fkey" FOREIGN KEY ("envelopeId") REFERENCES "Envelope"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "DocumentShareLink" ADD CONSTRAINT "DocumentShareLink_envelopeId_fkey" FOREIGN KEY ("envelopeId") REFERENCES "Envelope"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "TemplateDirectLink" ADD CONSTRAINT "TemplateDirectLink_envelopeId_fkey" FOREIGN KEY ("envelopeId") REFERENCES "Envelope"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@ -0,0 +1,11 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- Added the required column `envelopeId` to the `Document` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "Document" ADD COLUMN "envelopeId" TEXT NOT NULL;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Document" ADD CONSTRAINT "Document_envelopeId_fkey" FOREIGN KEY ("envelopeId") REFERENCES "Envelope"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@ -64,8 +64,7 @@ model User {
|
||||
twoFactorBackupCodes String?
|
||||
|
||||
folders Folder[]
|
||||
documents Document[]
|
||||
templates Template[]
|
||||
envelopes Envelope[]
|
||||
|
||||
verificationTokens VerificationToken[]
|
||||
apiTokens ApiToken[]
|
||||
@ -348,8 +347,7 @@ model Folder {
|
||||
pinned Boolean @default(false)
|
||||
parentId String?
|
||||
parent Folder? @relation("FolderToFolder", fields: [parentId], references: [id], onDelete: Cascade)
|
||||
documents Document[]
|
||||
templates Template[]
|
||||
envelopes Envelope[]
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
subfolders Folder[] @relation("FolderToFolder")
|
||||
@ -362,53 +360,79 @@ model Folder {
|
||||
@@index([type])
|
||||
}
|
||||
|
||||
/// @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())
|
||||
qrToken String? /// @zod.string.describe("The token for viewing the document using the QR code on the certificate.")
|
||||
externalId String? /// @zod.string.describe("A custom external ID you can use to identify the document.")
|
||||
enum EnvelopeType {
|
||||
DOCUMENT
|
||||
TEMPLATE
|
||||
}
|
||||
|
||||
model Envelope {
|
||||
id String @id @default(cuid())
|
||||
secondaryId String @unique
|
||||
externalId String? /// @zod.string.describe("A custom external ID you can use to identify the document.")
|
||||
|
||||
type EnvelopeType
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
completedAt DateTime?
|
||||
deletedAt DateTime?
|
||||
|
||||
title String
|
||||
status DocumentStatus @default(DRAFT)
|
||||
source DocumentSource
|
||||
|
||||
useLegacyFieldInsertion Boolean @default(false)
|
||||
|
||||
documents Document[]
|
||||
recipients Recipient[]
|
||||
fields Field[]
|
||||
shareLinks DocumentShareLink[]
|
||||
auditLogs DocumentAuditLog[]
|
||||
|
||||
// Envelope settings
|
||||
authOptions Json? /// [DocumentAuthOptions] @zod.custom.use(ZDocumentAuthOptionsSchema)
|
||||
formValues Json? /// [DocumentFormValues] @zod.custom.use(ZDocumentFormValuesSchema)
|
||||
visibility DocumentVisibility @default(EVERYONE)
|
||||
|
||||
// Template specific fields.
|
||||
publicTitle String @default("")
|
||||
publicDescription String @default("")
|
||||
directLink TemplateDirectLink?
|
||||
templateId Int? // Todo: Migrate from templateId -> This @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
|
||||
// Relations
|
||||
userId Int /// @zod.number.describe("The ID of the user that created this document.")
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
teamId Int
|
||||
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
|
||||
|
||||
authOptions Json? /// [DocumentAuthOptions] @zod.custom.use(ZDocumentAuthOptionsSchema)
|
||||
formValues Json? /// [DocumentFormValues] @zod.custom.use(ZDocumentFormValuesSchema)
|
||||
visibility DocumentVisibility @default(EVERYONE)
|
||||
title String
|
||||
status DocumentStatus @default(DRAFT)
|
||||
recipients Recipient[]
|
||||
fields Field[]
|
||||
shareLinks DocumentShareLink[]
|
||||
folder Folder? @relation(fields: [folderId], references: [id], onDelete: SetNull)
|
||||
folderId String?
|
||||
|
||||
documentMetaId String @unique
|
||||
documentMeta DocumentMeta @relation(fields: [documentMetaId], references: [id])
|
||||
}
|
||||
|
||||
/// @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())
|
||||
|
||||
qrToken String? /// @zod.string.describe("The token for viewing the document using the QR code on the certificate.")
|
||||
title String
|
||||
|
||||
documentDataId String
|
||||
documentMeta DocumentMeta?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
completedAt DateTime?
|
||||
deletedAt DateTime?
|
||||
templateId Int?
|
||||
source DocumentSource
|
||||
documentData DocumentData @relation(fields: [documentDataId], references: [id], onDelete: Cascade)
|
||||
|
||||
useLegacyFieldInsertion Boolean @default(false)
|
||||
|
||||
documentData DocumentData @relation(fields: [documentDataId], references: [id], onDelete: Cascade)
|
||||
template Template? @relation(fields: [templateId], references: [id], onDelete: SetNull)
|
||||
|
||||
auditLogs DocumentAuditLog[]
|
||||
folder Folder? @relation(fields: [folderId], references: [id], onDelete: SetNull)
|
||||
folderId String?
|
||||
envelopeId String
|
||||
envelope Envelope @relation(fields: [envelopeId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([documentDataId])
|
||||
@@index([userId])
|
||||
@@index([status])
|
||||
@@index([folderId])
|
||||
}
|
||||
|
||||
model DocumentAuditLog {
|
||||
id String @id @default(cuid())
|
||||
documentId Int
|
||||
envelopeId String
|
||||
createdAt DateTime @default(now())
|
||||
type String
|
||||
data Json
|
||||
@ -420,7 +444,7 @@ model DocumentAuditLog {
|
||||
userAgent String?
|
||||
ipAddress String?
|
||||
|
||||
Document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
|
||||
envelope Envelope @relation(fields: [envelopeId], references: [id], onDelete: Cascade)
|
||||
}
|
||||
|
||||
enum DocumentDataType {
|
||||
@ -440,7 +464,6 @@ model DocumentData {
|
||||
data String
|
||||
initialData String
|
||||
document Document?
|
||||
template Template?
|
||||
}
|
||||
|
||||
enum DocumentDistributionMethod {
|
||||
@ -471,11 +494,8 @@ model DocumentMeta {
|
||||
emailReplyTo String?
|
||||
emailId String?
|
||||
|
||||
documentId Int? @unique
|
||||
document Document? @relation(fields: [documentId], references: [id], onDelete: Cascade)
|
||||
|
||||
templateId Int? @unique
|
||||
template Template? @relation(fields: [templateId], references: [id], onDelete: Cascade)
|
||||
envelopeId String?
|
||||
envelope Envelope?
|
||||
}
|
||||
|
||||
enum ReadStatus {
|
||||
@ -505,8 +525,7 @@ enum RecipientRole {
|
||||
/// @zod.import(["import { ZRecipientAuthOptionsSchema } from '@documenso/lib/types/document-auth';"])
|
||||
model Recipient {
|
||||
id Int @id @default(autoincrement())
|
||||
documentId Int?
|
||||
templateId Int?
|
||||
envelopeId String
|
||||
email String @db.VarChar(255)
|
||||
name String @default("") @db.VarChar(255)
|
||||
token String
|
||||
@ -520,15 +539,12 @@ model Recipient {
|
||||
readStatus ReadStatus @default(NOT_OPENED)
|
||||
signingStatus SigningStatus @default(NOT_SIGNED)
|
||||
sendStatus SendStatus @default(NOT_SENT)
|
||||
document Document? @relation(fields: [documentId], references: [id], onDelete: Cascade)
|
||||
template Template? @relation(fields: [templateId], references: [id], onDelete: Cascade)
|
||||
envelope Envelope @relation(fields: [envelopeId], references: [id], onDelete: Cascade)
|
||||
fields Field[]
|
||||
signatures Signature[]
|
||||
|
||||
@@unique([documentId, email])
|
||||
@@unique([templateId, email])
|
||||
@@index([documentId])
|
||||
@@index([templateId])
|
||||
@@unique([envelopeId, email])
|
||||
@@index([envelopeId])
|
||||
@@index([token])
|
||||
}
|
||||
|
||||
@ -550,8 +566,7 @@ enum FieldType {
|
||||
model Field {
|
||||
id Int @id @default(autoincrement())
|
||||
secondaryId String @unique @default(cuid())
|
||||
documentId Int?
|
||||
templateId Int?
|
||||
envelopeId String
|
||||
recipientId Int
|
||||
type FieldType
|
||||
page Int /// @zod.number.describe("The page number of the field on the document. Starts from 1.")
|
||||
@ -561,14 +576,12 @@ model Field {
|
||||
height Decimal @default(-1)
|
||||
customText String
|
||||
inserted Boolean
|
||||
document Document? @relation(fields: [documentId], references: [id], onDelete: Cascade)
|
||||
template Template? @relation(fields: [templateId], references: [id], onDelete: Cascade)
|
||||
envelope Envelope @relation(fields: [envelopeId], references: [id], onDelete: Cascade)
|
||||
recipient Recipient @relation(fields: [recipientId], references: [id], onDelete: Cascade)
|
||||
signature Signature?
|
||||
fieldMeta Json? /// [FieldMeta] @zod.custom.use(ZFieldMetaNotOptionalSchema)
|
||||
|
||||
@@index([documentId])
|
||||
@@index([templateId])
|
||||
@@index([envelopeId])
|
||||
@@index([recipientId])
|
||||
}
|
||||
|
||||
@ -590,13 +603,13 @@ model DocumentShareLink {
|
||||
id Int @id @default(autoincrement())
|
||||
email String
|
||||
slug String @unique
|
||||
documentId Int
|
||||
envelopeId String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
|
||||
envelope Envelope @relation(fields: [envelopeId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([documentId, email])
|
||||
@@unique([envelopeId, email])
|
||||
}
|
||||
|
||||
enum OrganisationType {
|
||||
@ -807,8 +820,7 @@ model Team {
|
||||
|
||||
profile TeamProfile?
|
||||
|
||||
documents Document[]
|
||||
templates Template[]
|
||||
envelopes Envelope[]
|
||||
folders Folder[]
|
||||
apiTokens ApiToken[]
|
||||
webhooks Webhook[]
|
||||
@ -841,58 +853,26 @@ model TeamEmailVerification {
|
||||
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
|
||||
}
|
||||
|
||||
enum TemplateType {
|
||||
// TODO: USE THIS
|
||||
// TODO: USE THIS
|
||||
// TODO: USE THIS
|
||||
// TODO: USE THIS
|
||||
enum TemplateDirectLinkType {
|
||||
PUBLIC
|
||||
PRIVATE
|
||||
}
|
||||
|
||||
/// @zod.import(["import { ZDocumentAuthOptionsSchema } from '@documenso/lib/types/document-auth';"])
|
||||
model Template {
|
||||
id Int @id @default(autoincrement())
|
||||
externalId String?
|
||||
type TemplateType @default(PRIVATE)
|
||||
title String
|
||||
visibility DocumentVisibility @default(EVERYONE)
|
||||
authOptions Json? /// [DocumentAuthOptions] @zod.custom.use(ZDocumentAuthOptionsSchema)
|
||||
templateMeta DocumentMeta?
|
||||
templateDocumentDataId String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
publicTitle String @default("")
|
||||
publicDescription String @default("")
|
||||
|
||||
useLegacyFieldInsertion Boolean @default(false)
|
||||
|
||||
userId Int
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
teamId Int
|
||||
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
|
||||
|
||||
templateDocumentData DocumentData @relation(fields: [templateDocumentDataId], references: [id], onDelete: Cascade)
|
||||
|
||||
recipients Recipient[]
|
||||
fields Field[]
|
||||
directLink TemplateDirectLink?
|
||||
documents Document[]
|
||||
|
||||
folder Folder? @relation(fields: [folderId], references: [id], onDelete: SetNull)
|
||||
folderId String?
|
||||
|
||||
@@unique([templateDocumentDataId])
|
||||
@@index([userId])
|
||||
}
|
||||
|
||||
model TemplateDirectLink {
|
||||
id String @id @unique @default(cuid())
|
||||
templateId Int @unique
|
||||
token String @unique
|
||||
createdAt DateTime @default(now())
|
||||
id String @id @unique @default(cuid())
|
||||
envelopeId String @unique
|
||||
token String @unique
|
||||
createdAt DateTime @default(now())
|
||||
enabled Boolean
|
||||
type TemplateDirectLinkType
|
||||
|
||||
directTemplateRecipientId Int
|
||||
|
||||
template Template @relation(fields: [templateId], references: [id], onDelete: Cascade)
|
||||
envelope Envelope @relation(fields: [envelopeId], references: [id], onDelete: Cascade)
|
||||
}
|
||||
|
||||
model SiteSettings {
|
||||
|
||||
59
packages/prisma/types/document-legacy-schema.ts
Normal file
59
packages/prisma/types/document-legacy-schema.ts
Normal file
@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Legacy Document schema to confirm backwards API compatibility since
|
||||
* we migrated Documents to Envelopes.
|
||||
*/
|
||||
import { z } from 'zod';
|
||||
|
||||
import { ZDocumentAuthOptionsSchema } from '@documenso/lib/types/document-auth';
|
||||
import { ZDocumentFormValuesSchema } from '@documenso/lib/types/document-form-values';
|
||||
|
||||
import DocumentStatusSchema from '../generated/zod/inputTypeSchemas/DocumentStatusSchema';
|
||||
import DocumentVisibilitySchema from '../generated/zod/inputTypeSchemas/DocumentVisibilitySchema';
|
||||
|
||||
const DocumentSourceSchema = z.enum(['DOCUMENT', 'TEMPLATE', 'TEMPLATE_DIRECT_LINK']);
|
||||
const DocumentTypeSchema = z.enum(['DOCUMENT', 'PUBLIC_TEMPLATE', 'PRIVATE_TEMPLATE']);
|
||||
|
||||
/////////////////////////////////////////
|
||||
// DOCUMENT SCHEMA
|
||||
/////////////////////////////////////////
|
||||
|
||||
export const LegacyDocumentSchema = z.object({
|
||||
type: DocumentTypeSchema,
|
||||
visibility: DocumentVisibilitySchema,
|
||||
status: DocumentStatusSchema,
|
||||
source: DocumentSourceSchema,
|
||||
id: z.number(),
|
||||
qrToken: z
|
||||
.string()
|
||||
.describe('The token for viewing the document using the QR code on the certificate.')
|
||||
.nullable(),
|
||||
externalId: z
|
||||
.string()
|
||||
.describe('A custom external ID you can use to identify the document.')
|
||||
.nullable(),
|
||||
secondaryDocumentId: z.number(),
|
||||
secondaryTemplateId: z.number(),
|
||||
publicTitle: z.string(),
|
||||
publicDescription: z.string(),
|
||||
createdFromDocumentId: z.number().nullable(),
|
||||
userId: z.number().describe('The ID of the user that created this document.'),
|
||||
teamId: z.number(),
|
||||
/**
|
||||
* [DocumentAuthOptions]
|
||||
*/
|
||||
authOptions: ZDocumentAuthOptionsSchema.nullable(),
|
||||
/**
|
||||
* [DocumentFormValues]
|
||||
*/
|
||||
formValues: ZDocumentFormValuesSchema.nullable(),
|
||||
title: z.string(),
|
||||
documentDataId: z.string(),
|
||||
createdAt: z.coerce.date(),
|
||||
updatedAt: z.coerce.date(),
|
||||
completedAt: z.coerce.date().nullable(),
|
||||
deletedAt: z.coerce.date().nullable(),
|
||||
useLegacyFieldInsertion: z.boolean(),
|
||||
folderId: z.string().nullable(),
|
||||
});
|
||||
|
||||
export type Document = z.infer<typeof LegacyDocumentSchema>;
|
||||
36
packages/prisma/types/template-legacy-schema.ts
Normal file
36
packages/prisma/types/template-legacy-schema.ts
Normal file
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Legacy Template schema to confirm backwards API compatibility since
|
||||
* we removed the "Template" prisma schema model.
|
||||
*/
|
||||
import { z } from 'zod';
|
||||
|
||||
import { ZDocumentAuthOptionsSchema } from '@documenso/lib/types/document-auth';
|
||||
|
||||
import { DocumentVisibilitySchema } from '../generated/zod/inputTypeSchemas/DocumentVisibilitySchema';
|
||||
|
||||
export const TemplateTypeSchema = z.enum(['PUBLIC', 'PRIVATE']);
|
||||
|
||||
export type TemplateTypeType = `${z.infer<typeof TemplateTypeSchema>}`;
|
||||
|
||||
export const TemplateSchema = z.object({
|
||||
type: TemplateTypeSchema,
|
||||
visibility: DocumentVisibilitySchema,
|
||||
id: z.number(),
|
||||
externalId: z.string().nullable(),
|
||||
title: z.string(),
|
||||
/**
|
||||
* [DocumentAuthOptions]
|
||||
*/
|
||||
authOptions: ZDocumentAuthOptionsSchema.nullable(),
|
||||
templateDocumentDataId: z.string(),
|
||||
createdAt: z.coerce.date(),
|
||||
updatedAt: z.coerce.date(),
|
||||
publicTitle: z.string(),
|
||||
publicDescription: z.string(),
|
||||
useLegacyFieldInsertion: z.boolean(),
|
||||
userId: z.number(),
|
||||
teamId: z.number(),
|
||||
folderId: z.string().nullable(),
|
||||
});
|
||||
|
||||
export type Template = z.infer<typeof TemplateSchema>;
|
||||
Reference in New Issue
Block a user