mirror of
https://github.com/documenso/documenso.git
synced 2025-11-12 15:53:02 +10:00
feat: templates
This commit is contained in:
committed by
Mythie
parent
6d34ebd91b
commit
31a9127c9e
@ -0,0 +1,52 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "TemplateStatus" AS ENUM ('PUBLIC', 'PRIVATE');
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Template" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"userId" INTEGER NOT NULL,
|
||||
"title" TEXT NOT NULL,
|
||||
"description" TEXT,
|
||||
"status" "TemplateStatus" NOT NULL DEFAULT 'PRIVATE',
|
||||
"templateDataId" TEXT NOT NULL,
|
||||
|
||||
CONSTRAINT "Template_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "TemplateData" (
|
||||
"id" TEXT NOT NULL,
|
||||
"type" "DocumentDataType" NOT NULL,
|
||||
"data" TEXT NOT NULL,
|
||||
"initialData" TEXT NOT NULL,
|
||||
|
||||
CONSTRAINT "TemplateData_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "TemplateField" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"templateId" INTEGER NOT NULL,
|
||||
"type" "FieldType" NOT NULL,
|
||||
"page" INTEGER NOT NULL,
|
||||
"positionX" DECIMAL(65,30) NOT NULL DEFAULT 0,
|
||||
"positionY" DECIMAL(65,30) NOT NULL DEFAULT 0,
|
||||
"width" DECIMAL(65,30) NOT NULL DEFAULT -1,
|
||||
"height" DECIMAL(65,30) NOT NULL DEFAULT -1,
|
||||
"customText" TEXT NOT NULL,
|
||||
"inserted" BOOLEAN NOT NULL,
|
||||
|
||||
CONSTRAINT "TemplateField_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Template_templateDataId_key" ON "Template"("templateDataId");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Template" ADD CONSTRAINT "Template_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Template" ADD CONSTRAINT "Template_templateDataId_fkey" FOREIGN KEY ("templateDataId") REFERENCES "TemplateData"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "TemplateField" ADD CONSTRAINT "TemplateField_templateId_fkey" FOREIGN KEY ("templateId") REFERENCES "Template"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@ -0,0 +1,15 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- The `status` column on the `Template` table would be dropped and recreated. This will lead to data loss if there is data in the column.
|
||||
|
||||
*/
|
||||
-- CreateEnum
|
||||
CREATE TYPE "TemplateType" AS ENUM ('PUBLIC', 'PRIVATE');
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Template" DROP COLUMN "status",
|
||||
ADD COLUMN "status" "TemplateType" NOT NULL DEFAULT 'PRIVATE';
|
||||
|
||||
-- DropEnum
|
||||
DROP TYPE "TemplateStatus";
|
||||
@ -0,0 +1,14 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the `TemplateData` table. If the table is not empty, all the data it contains will be lost.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Template" DROP CONSTRAINT "Template_templateDataId_fkey";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "TemplateData";
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Template" ADD CONSTRAINT "Template_templateDataId_fkey" FOREIGN KEY ("templateDataId") REFERENCES "DocumentData"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@ -0,0 +1,8 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `inserted` on the `TemplateField` table. All the data in the column will be lost.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "TemplateField" DROP COLUMN "inserted";
|
||||
@ -0,0 +1,8 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- Added the required column `documentName` to the `Template` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "Template" ADD COLUMN "documentName" TEXT NOT NULL;
|
||||
@ -0,0 +1,9 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- Added the required column `updatedAt` to the `Template` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "Template" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL;
|
||||
@ -0,0 +1,51 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `description` on the `Template` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `documentName` on the `Template` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `status` on the `Template` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `templateDataId` on the `Template` table. All the data in the column will be lost.
|
||||
- A unique constraint covering the columns `[tempateDocumentDataId]` on the table `Template` will be added. If there are existing duplicate values, this will fail.
|
||||
- Added the required column `tempateDocumentDataId` to the `Template` table without a default value. This is not possible if the table is not empty.
|
||||
- Added the required column `inserted` to the `TemplateField` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Template" DROP CONSTRAINT "Template_templateDataId_fkey";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "Template_templateDataId_key";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Template" DROP COLUMN "description",
|
||||
DROP COLUMN "documentName",
|
||||
DROP COLUMN "status",
|
||||
DROP COLUMN "templateDataId",
|
||||
ADD COLUMN "tempateDocumentDataId" TEXT NOT NULL,
|
||||
ADD COLUMN "type" "TemplateType" NOT NULL DEFAULT 'PRIVATE',
|
||||
ALTER COLUMN "updatedAt" SET DEFAULT CURRENT_TIMESTAMP;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "TemplateField" ADD COLUMN "inserted" BOOLEAN NOT NULL,
|
||||
ADD COLUMN "recipientId" INTEGER;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "TemplateRecipient" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"templateId" INTEGER NOT NULL,
|
||||
"placeholder" VARCHAR(255) NOT NULL,
|
||||
|
||||
CONSTRAINT "TemplateRecipient_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Template_tempateDocumentDataId_key" ON "Template"("tempateDocumentDataId");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Template" ADD CONSTRAINT "Template_tempateDocumentDataId_fkey" FOREIGN KEY ("tempateDocumentDataId") REFERENCES "DocumentData"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "TemplateRecipient" ADD CONSTRAINT "TemplateRecipient_templateId_fkey" FOREIGN KEY ("templateId") REFERENCES "Template"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "TemplateField" ADD CONSTRAINT "TemplateField_recipientId_fkey" FOREIGN KEY ("recipientId") REFERENCES "TemplateRecipient"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@ -0,0 +1,23 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `tempateDocumentDataId` on the `Template` table. All the data in the column will be lost.
|
||||
- A unique constraint covering the columns `[templateDocumentDataId]` on the table `Template` will be added. If there are existing duplicate values, this will fail.
|
||||
- Added the required column `templateDocumentDataId` to the `Template` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Template" DROP CONSTRAINT "Template_tempateDocumentDataId_fkey";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "Template_tempateDocumentDataId_key";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Template" DROP COLUMN "tempateDocumentDataId",
|
||||
ADD COLUMN "templateDocumentDataId" TEXT NOT NULL;
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Template_templateDocumentDataId_key" ON "Template"("templateDocumentDataId");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Template" ADD CONSTRAINT "Template_templateDocumentDataId_fkey" FOREIGN KEY ("templateDocumentDataId") REFERENCES "DocumentData"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@ -0,0 +1,8 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- Added the required column `email` to the `TemplateRecipient` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "TemplateRecipient" ADD COLUMN "email" VARCHAR(255) NOT NULL;
|
||||
@ -0,0 +1,8 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- Added the required column `token` to the `TemplateRecipient` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "TemplateRecipient" ADD COLUMN "token" TEXT NOT NULL;
|
||||
@ -0,0 +1,5 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Recipient" ADD COLUMN "templateToken" TEXT;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "TemplateRecipient" ADD COLUMN "templateToken" TEXT;
|
||||
@ -0,0 +1,10 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `placeholder` on the `TemplateRecipient` table. All the data in the column will be lost.
|
||||
- Added the required column `name` to the `TemplateRecipient` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "TemplateRecipient" DROP COLUMN "placeholder",
|
||||
ADD COLUMN "name" VARCHAR(255) NOT NULL;
|
||||
@ -0,0 +1,54 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the `TemplateField` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `TemplateRecipient` table. If the table is not empty, all the data it contains will be lost.
|
||||
- A unique constraint covering the columns `[templateId,email]` on the table `Recipient` will be added. If there are existing duplicate values, this will fail.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Field" DROP CONSTRAINT "Field_recipientId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "TemplateField" DROP CONSTRAINT "TemplateField_recipientId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "TemplateField" DROP CONSTRAINT "TemplateField_templateId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "TemplateRecipient" DROP CONSTRAINT "TemplateRecipient_templateId_fkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Field" ADD COLUMN "templateId" INTEGER,
|
||||
ALTER COLUMN "documentId" DROP NOT NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Recipient" ADD COLUMN "templateId" INTEGER,
|
||||
ALTER COLUMN "documentId" DROP NOT NULL,
|
||||
ALTER COLUMN "readStatus" DROP NOT NULL,
|
||||
ALTER COLUMN "signingStatus" DROP NOT NULL,
|
||||
ALTER COLUMN "sendStatus" DROP NOT NULL;
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "TemplateField";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "TemplateRecipient";
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Field_templateId_idx" ON "Field"("templateId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Recipient_templateId_idx" ON "Recipient"("templateId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Recipient_templateId_email_key" ON "Recipient"("templateId", "email");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Recipient" ADD CONSTRAINT "Recipient_templateId_fkey" FOREIGN KEY ("templateId") REFERENCES "Template"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Field" ADD CONSTRAINT "Field_templateId_fkey" FOREIGN KEY ("templateId") REFERENCES "Template"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Field" ADD CONSTRAINT "Field_recipientId_fkey" FOREIGN KEY ("recipientId") REFERENCES "Recipient"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@ -40,6 +40,7 @@ model User {
|
||||
twoFactorEnabled Boolean @default(false)
|
||||
twoFactorBackupCodes String?
|
||||
VerificationToken VerificationToken[]
|
||||
Template Template[]
|
||||
|
||||
@@index([email])
|
||||
}
|
||||
@ -154,6 +155,7 @@ model DocumentData {
|
||||
data String
|
||||
initialData String
|
||||
Document Document?
|
||||
Template Template?
|
||||
}
|
||||
|
||||
model DocumentMeta {
|
||||
@ -180,22 +182,27 @@ enum SigningStatus {
|
||||
}
|
||||
|
||||
model Recipient {
|
||||
id Int @id @default(autoincrement())
|
||||
documentId Int
|
||||
email String @db.VarChar(255)
|
||||
name String @default("") @db.VarChar(255)
|
||||
id Int @id @default(autoincrement())
|
||||
documentId Int?
|
||||
templateId Int?
|
||||
email String @db.VarChar(255)
|
||||
name String @default("") @db.VarChar(255)
|
||||
token String
|
||||
templateToken String?
|
||||
expired DateTime?
|
||||
signedAt DateTime?
|
||||
readStatus ReadStatus @default(NOT_OPENED)
|
||||
signingStatus SigningStatus @default(NOT_SIGNED)
|
||||
sendStatus SendStatus @default(NOT_SENT)
|
||||
Document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
|
||||
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)
|
||||
Field Field[]
|
||||
Signature Signature[]
|
||||
|
||||
@@unique([documentId, email])
|
||||
@@unique([templateId, email])
|
||||
@@index([documentId])
|
||||
@@index([templateId])
|
||||
@@index([token])
|
||||
}
|
||||
|
||||
@ -210,7 +217,8 @@ enum FieldType {
|
||||
|
||||
model Field {
|
||||
id Int @id @default(autoincrement())
|
||||
documentId Int
|
||||
documentId Int?
|
||||
templateId Int?
|
||||
recipientId Int?
|
||||
type FieldType
|
||||
page Int
|
||||
@ -220,11 +228,13 @@ model Field {
|
||||
height Decimal @default(-1)
|
||||
customText String
|
||||
inserted Boolean
|
||||
Document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
|
||||
Recipient Recipient? @relation(fields: [recipientId], references: [id], onDelete: Cascade)
|
||||
Document Document? @relation(fields: [documentId], references: [id], onDelete: Cascade)
|
||||
Template Template? @relation(fields: [templateId], references: [id], onDelete: Cascade)
|
||||
Recipient Recipient? @relation(fields: [recipientId], references: [id])
|
||||
Signature Signature?
|
||||
|
||||
@@index([documentId])
|
||||
@@index([templateId])
|
||||
@@index([recipientId])
|
||||
}
|
||||
|
||||
@ -254,3 +264,24 @@ model DocumentShareLink {
|
||||
|
||||
@@unique([documentId, email])
|
||||
}
|
||||
|
||||
enum TemplateType {
|
||||
PUBLIC
|
||||
PRIVATE
|
||||
}
|
||||
|
||||
model Template {
|
||||
id Int @id @default(autoincrement())
|
||||
userId Int
|
||||
User User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
title String
|
||||
type TemplateType @default(PRIVATE)
|
||||
templateDocumentDataId String
|
||||
templateDocumentData DocumentData @relation(fields: [templateDocumentDataId], references: [id], onDelete: Cascade)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
Recipient Recipient[]
|
||||
Field Field[]
|
||||
|
||||
@@unique([templateDocumentDataId])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user