Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat(prisma): adjust viewer table model

Marc Seitz376bf072fa57
diff --git a/pages/api/jobs/send-dataroom-view-invitation.ts b/pages/api/jobs/send-dataroom-view-invitation.ts
index 98080ce2..2b9305e2 100644
--- a/pages/api/jobs/send-dataroom-view-invitation.ts
+++ b/pages/api/jobs/send-dataroom-view-invitation.ts
@@ -42,7 +42,6 @@ export default async function handle(
viewer = await prisma.viewer.findUnique({
where: {
id: viewerId,
- dataroomId: dataroomId,
},
select: {
email: true,
diff --git a/prisma/migrations/20240921000000_add_viewer_migration/migration.sql b/prisma/migrations/20240921000000_add_viewer_migration/migration.sql
new file mode 100644
index 00000000..95e896a0
--- /dev/null
+++ b/prisma/migrations/20240921000000_add_viewer_migration/migration.sql
@@ -0,0 +1,16 @@
+-- DropForeignKey
+ALTER TABLE "Viewer" DROP CONSTRAINT "Viewer_dataroomId_fkey";
+
+-- DropIndex
+DROP INDEX "Viewer_dataroomId_email_key";
+
+-- AlterTable
+ALTER TABLE "Viewer" ALTER COLUMN "dataroomId" DROP NOT NULL,
+ALTER COLUMN "teamId" SET NOT NULL;
+
+-- CreateIndex
+CREATE UNIQUE INDEX "Viewer_teamId_email_key" ON "Viewer"("teamId", "email");
+
+-- AddForeignKey
+ALTER TABLE "Viewer" ADD CONSTRAINT "Viewer_dataroomId_fkey" FOREIGN KEY ("dataroomId") REFERENCES "Dataroom"("id") ON DELETE SET NULL ON UPDATE CASCADE;
+
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index c7792b26..dd8ced26 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -125,27 +125,27 @@ model VerificationToken {
}
model Document {
- id String @id @default(cuid())
- name String
- description String?
- file String // This should be a reference to where the file is stored (S3, Google Cloud Storage, etc.)
- originalFile String? // This should be a reference to the original file like pptx, xlsx, etc. (S3, Google Cloud Storage, etc.)
- type String? // This should be a reference to the file type (pdf, sheet, etc.)
- contentType String? // This should be the actual contentType of the file like application/pdf, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, etc.
- storageType DocumentStorageType @default(VERCEL_BLOB)
- numPages Int? // This should be a reference to the number of pages in the document
- owner User? @relation(fields: [ownerId], references: [id], onDelete: SetNull)
- teamId String
- team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
- ownerId String? // This field holds the foreign key.
- assistantEnabled Boolean @default(false) // This indicates if assistant is enabled for this document
+ id String @id @default(cuid())
+ name String
+ description String?
+ file String // This should be a reference to where the file is stored (S3, Google Cloud Storage, etc.)
+ originalFile String? // This should be a reference to the original file like pptx, xlsx, etc. (S3, Google Cloud Storage, etc.)
+ type String? // This should be a reference to the file type (pdf, sheet, etc.)
+ contentType String? // This should be the actual contentType of the file like application/pdf, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, etc.
+ storageType DocumentStorageType @default(VERCEL_BLOB)
+ numPages Int? // This should be a reference to the number of pages in the document
+ owner User? @relation(fields: [ownerId], references: [id], onDelete: SetNull)
+ teamId String
+ team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
+ ownerId String? // This field holds the foreign key.
+ assistantEnabled Boolean @default(false) // This indicates if assistant is enabled for this document
advancedExcelEnabled Boolean @default(false) // This indicates if advanced Excel is enabled for this document
- createdAt DateTime @default(now())
- updatedAt DateTime @updatedAt
- links Link[]
- views View[]
- versions DocumentVersion[]
- conversations Conversation[]
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+ links Link[]
+ views View[]
+ versions DocumentVersion[]
+ conversations Conversation[]
folderId String? // Optional Folder ID for documents in folders
folder Folder? @relation(fields: [folderId], references: [id], onDelete: SetNull)
@@ -339,10 +339,10 @@ model Viewer {
verified Boolean @default(false) // Whether the viewer email has been verified
invitedAt DateTime? // This is the time the viewer was invited
- dataroomId String
- dataroom Dataroom @relation(fields: [dataroomId], references: [id], onDelete: Cascade)
- teamId String?
- team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)
+ dataroomId String?
+ dataroom Dataroom? @relation(fields: [dataroomId], references: [id], onDelete: SetNull)
+ teamId String
+ team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
views View[]
groups ViewerGroupMembership[]
@@ -350,7 +350,7 @@ model Viewer {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
- @@unique([dataroomId, email])
+ @@unique([teamId, email])
@@index([teamId])
@@index([dataroomId])
}