From 5de5d8b0fbe74dae2f0c227ab27c1790f6549fe2 Mon Sep 17 00:00:00 2001 From: Mythie Date: Mon, 30 Oct 2023 16:58:51 +1100 Subject: [PATCH] feat: add database indexes --- .../migration.sql | 23 +++++++++++++++++++ packages/prisma/schema.prisma | 11 +++++++++ 2 files changed, 34 insertions(+) create mode 100644 packages/prisma/migrations/20231030055821_add_database_indexes/migration.sql diff --git a/packages/prisma/migrations/20231030055821_add_database_indexes/migration.sql b/packages/prisma/migrations/20231030055821_add_database_indexes/migration.sql new file mode 100644 index 000000000..ca28bab8c --- /dev/null +++ b/packages/prisma/migrations/20231030055821_add_database_indexes/migration.sql @@ -0,0 +1,23 @@ +-- CreateIndex +CREATE INDEX "Document_userId_idx" ON "Document"("userId"); + +-- CreateIndex +CREATE INDEX "Document_status_idx" ON "Document"("status"); + +-- CreateIndex +CREATE INDEX "Field_documentId_idx" ON "Field"("documentId"); + +-- CreateIndex +CREATE INDEX "Field_recipientId_idx" ON "Field"("recipientId"); + +-- CreateIndex +CREATE INDEX "Recipient_documentId_idx" ON "Recipient"("documentId"); + +-- CreateIndex +CREATE INDEX "Recipient_token_idx" ON "Recipient"("token"); + +-- CreateIndex +CREATE INDEX "Signature_recipientId_idx" ON "Signature"("recipientId"); + +-- CreateIndex +CREATE INDEX "User_email_idx" ON "User"("email"); diff --git a/packages/prisma/schema.prisma b/packages/prisma/schema.prisma index 8dfe5ca0d..f273f6c3f 100644 --- a/packages/prisma/schema.prisma +++ b/packages/prisma/schema.prisma @@ -36,6 +36,8 @@ model User { Document Document[] Subscription Subscription? PasswordResetToken PasswordResetToken[] + + @@index([email]) } model PasswordResetToken { @@ -120,6 +122,8 @@ model Document { updatedAt DateTime @default(now()) @updatedAt @@unique([documentDataId]) + @@index([userId]) + @@index([status]) } enum DocumentDataType { @@ -175,6 +179,8 @@ model Recipient { Signature Signature[] @@unique([documentId, email]) + @@index([documentId]) + @@index([token]) } enum FieldType { @@ -201,6 +207,9 @@ model Field { Document Document @relation(fields: [documentId], references: [id], onDelete: Cascade) Recipient Recipient? @relation(fields: [recipientId], references: [id], onDelete: Cascade) Signature Signature? + + @@index([documentId]) + @@index([recipientId]) } model Signature { @@ -213,6 +222,8 @@ model Signature { Recipient Recipient @relation(fields: [recipientId], references: [id], onDelete: Cascade) Field Field @relation(fields: [fieldId], references: [id], onDelete: Restrict) + + @@index([recipientId]) } model DocumentShareLink {