mirror of
https://github.com/documenso/documenso.git
synced 2025-11-12 15:53:02 +10:00
fix: reverse meta relation and tidy code
This commit is contained in:
@ -0,0 +1,52 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `documentMetaId` on the `Document` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `customEmailBody` on the `DocumentMeta` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `customEmailSubject` on the `DocumentMeta` table. All the data in the column will be lost.
|
||||
- A unique constraint covering the columns `[documentId]` on the table `DocumentMeta` will be added. If there are existing duplicate values, this will fail.
|
||||
- Added the required column `documentId` to the `DocumentMeta` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Document" DROP CONSTRAINT "Document_documentMetaId_fkey";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "Document_documentMetaId_key";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "DocumentMeta"
|
||||
ADD COLUMN "documentId" INTEGER,
|
||||
ADD COLUMN "message" TEXT,
|
||||
ADD COLUMN "subject" TEXT;
|
||||
|
||||
-- Migrate data
|
||||
UPDATE "DocumentMeta" SET "documentId" = (
|
||||
SELECT "id" FROM "Document" WHERE "Document"."documentMetaId" = "DocumentMeta"."id"
|
||||
);
|
||||
|
||||
-- Migrate data
|
||||
UPDATE "DocumentMeta" SET "message" = "customEmailBody";
|
||||
|
||||
-- Migrate data
|
||||
UPDATE "DocumentMeta" SET "subject" = "customEmailSubject";
|
||||
|
||||
-- Prune data
|
||||
DELETE FROM "DocumentMeta" WHERE "documentId" IS NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Document" DROP COLUMN "documentMetaId";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "DocumentMeta"
|
||||
DROP COLUMN "customEmailBody",
|
||||
DROP COLUMN "customEmailSubject";
|
||||
|
||||
-- AlterColumn
|
||||
ALTER TABLE "DocumentMeta" ALTER COLUMN "documentId" SET NOT NULL;
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "DocumentMeta_documentId_key" ON "DocumentMeta"("documentId");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "DocumentMeta" ADD CONSTRAINT "DocumentMeta_documentId_fkey" FOREIGN KEY ("documentId") REFERENCES "Document"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@ -110,15 +110,12 @@ model Document {
|
||||
Field Field[]
|
||||
ShareLink DocumentShareLink[]
|
||||
documentDataId String
|
||||
documentData DocumentData @relation(fields: [documentDataId], references: [id], onDelete: Cascade)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
|
||||
documentMetaId String?
|
||||
DocumentMeta DocumentMeta? @relation(fields: [documentMetaId], references: [id], onDelete: Cascade)
|
||||
documentData DocumentData @relation(fields: [documentDataId], references: [id], onDelete: Cascade)
|
||||
documentMeta DocumentMeta?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
|
||||
@@unique([documentDataId])
|
||||
@@unique([documentMetaId])
|
||||
}
|
||||
|
||||
enum DocumentDataType {
|
||||
@ -136,10 +133,11 @@ model DocumentData {
|
||||
}
|
||||
|
||||
model DocumentMeta {
|
||||
id String @id @default(cuid())
|
||||
customEmailSubject String?
|
||||
customEmailBody String?
|
||||
Document Document?
|
||||
id String @id @default(cuid())
|
||||
subject String?
|
||||
message String?
|
||||
documentId Int @unique
|
||||
document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
|
||||
}
|
||||
|
||||
enum ReadStatus {
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { Document, DocumentData } from '@documenso/prisma/client';
|
||||
import { Document, DocumentData, DocumentMeta } from '@documenso/prisma/client';
|
||||
|
||||
export type DocumentWithData = Document & {
|
||||
documentData?: DocumentData | null;
|
||||
documentMeta?: DocumentMeta | null;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user