Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
refactor: change db table conversation to chat
Marc Seitzd848e55595d1
diff --git a/pages/api/assistants/threads/index.ts b/pages/api/assistants/threads/index.tsindex 1753de78..b9e93142 100644--- a/pages/api/assistants/threads/index.ts+++ b/pages/api/assistants/threads/index.ts@@ -18,8 +18,8 @@ export default async function handle(};try {- let conversation;- conversation = await prisma.conversation.findUnique({+ let chat;+ chat = await prisma.chat.findUnique({where: {userId_documentId: {userId,@@ -31,7 +31,7 @@ export default async function handle(},});- if (!conversation) {+ if (!chat) {// get fileId from document versionconst documentVersion = await prisma.documentVersion.findFirst({where: {@@ -48,7 +48,7 @@ export default async function handle(messages: [{role: "user",- content: "Initializing conversation with Papermark Assistant",+ content: "Initializing chat with Papermark Assistant",file_ids: [documentVersion?.fileId || ""],metadata: { intitialMessage: true },},@@ -56,7 +56,7 @@ export default async function handle(})).id;- conversation = await prisma.conversation.create({+ chat = await prisma.chat.create({data: {userId,threadId,@@ -68,12 +68,12 @@ export default async function handle(});}- const threadId = conversation.threadId;+ const threadId = chat.threadId;// get existing messages from thread, latest first (DESC)const { data } = await openai.beta.threads.messages.list(threadId);return res.status(200).json({- ...conversation,+ ...chat,messages: convertThreadMessagesToMessages(data),});} catch (error) {diff --git a/prisma/migrations/20250310000000_rename_conversation_table/migration.sql b/prisma/migrations/20250310000000_rename_conversation_table/migration.sqlnew file mode 100644index 00000000..5b09ce1b--- /dev/null+++ b/prisma/migrations/20250310000000_rename_conversation_table/migration.sql@@ -0,0 +1,13 @@+-- Rename the table (this preserves all data)+ALTER TABLE "Conversation" RENAME TO "Chat";++-- Rename constraints and indices to match the new table name+ALTER INDEX "Conversation_pkey" RENAME TO "Chat_pkey";+ALTER INDEX "Conversation_threadId_key" RENAME TO "Chat_threadId_key";+ALTER INDEX "Conversation_threadId_idx" RENAME TO "Chat_threadId_idx";+ALTER INDEX "Conversation_userId_documentId_key" RENAME TO "Chat_userId_documentId_key";+ALTER INDEX "Conversation_threadId_documentId_key" RENAME TO "Chat_threadId_documentId_key";++-- Rename foreign key constraints+ALTER TABLE "Chat" RENAME CONSTRAINT "Conversation_userId_fkey" TO "Chat_userId_fkey";+ALTER TABLE "Chat" RENAME CONSTRAINT "Conversation_documentId_fkey" TO "Chat_documentId_fkey";diff --git a/prisma/schema/dataroom.prisma b/prisma/schema/dataroom.prismanew file mode 100644index 00000000..7f148c3a--- /dev/null+++ b/prisma/schema/dataroom.prisma@@ -0,0 +1,141 @@+model Dataroom {+ id String @id @default(cuid())+ pId String @unique // This is the generated public ID for the dataroom dr_1234+ name String+ description String?+ teamId String+ team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)+ documents DataroomDocument[]+ folders DataroomFolder[]+ links Link[]+ views View[]+ viewers Viewer[]+ viewerGroups ViewerGroup[]+ brand DataroomBrand?++ // conversation+ conversationsEnabled Boolean @default(false)+ conversations Conversation[]++ createdAt DateTime @default(now())+ updatedAt DateTime @updatedAt++ @@index([teamId])+}++model DataroomDocument {+ id String @id @default(cuid())+ dataroomId String+ dataroom Dataroom @relation(fields: [dataroomId], references: [id], onDelete: Cascade)+ documentId String+ document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)+ folderId String?+ folder DataroomFolder? @relation(fields: [folderId], references: [id], onDelete: SetNull)+ orderIndex Int?++ conversations Conversation[]++ createdAt DateTime @default(now())+ updatedAt DateTime @updatedAt++ @@unique([dataroomId, documentId])+ @@index([folderId])+ @@index([dataroomId, folderId, orderIndex])+}++model DataroomFolder {+ id String @id @default(cuid())+ name String+ path String // the materialized path to the folder; starts always with "/"+ parentId String?+ documents DataroomDocument[]+ childFolders DataroomFolder[] @relation("SubFolders")+ parentFolder DataroomFolder? @relation("SubFolders", fields: [parentId], references: [id], onDelete: SetNull)+ dataroomId String+ dataroom Dataroom @relation(fields: [dataroomId], references: [id], onDelete: Cascade)+ orderIndex Int?++ createdAt DateTime @default(now())+ updatedAt DateTime @updatedAt++ @@unique([dataroomId, path])+ @@index([parentId])+ @@index([dataroomId, parentId, orderIndex])+}++model DataroomBrand {+ id String @id @default(cuid())+ logo String? // This should be a reference to where the file is stored (S3, Google Cloud Storage, etc.)+ banner String? // This should be a reference to where the file is stored (S3, Google Cloud Storage, etc.)+ brandColor String? // This should be a reference to the brand color+ accentColor String? // This should be a reference to the accent color+ dataroomId String @unique+ dataroom Dataroom @relation(fields: [dataroomId], references: [id], onDelete: Cascade)++ createdAt DateTime @default(now())+ updatedAt DateTime @updatedAt+}++model ViewerGroup {+ id String @id @default(cuid())+ name String+ members ViewerGroupMembership[]+ domains String[]+ links Link[]+ accessControls ViewerGroupAccessControls[]+ allowAll Boolean @default(false)++ dataroomId String+ dataroom Dataroom @relation(fields: [dataroomId], references: [id], onDelete: Cascade)+ teamId String+ team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)++ views View[]+ conversations Conversation[]++ createdAt DateTime @default(now())+ updatedAt DateTime @updatedAt++ @@index([dataroomId])+ @@index([teamId])+}++model ViewerGroupMembership {+ id String @id @default(cuid())+ viewerId String+ viewer Viewer @relation(fields: [viewerId], references: [id], onDelete: Cascade)+ groupId String+ group ViewerGroup @relation(fields: [groupId], references: [id], onDelete: Cascade)++ createdAt DateTime @default(now())+ updatedAt DateTime @updatedAt++ @@unique([viewerId, groupId])+ @@index([viewerId])+ @@index([groupId])+}++model ViewerGroupAccessControls {+ id String @id @default(cuid())+ groupId String+ group ViewerGroup @relation(fields: [groupId], references: [id], onDelete: Cascade)++ // Access control for items (documents or dataroom items)+ itemId String // This can be a document ID or a dataroom item ID+ itemType ItemType // Enum: DATAROOM_DOCUMENT, DATAROOM_FOLDER++ // Granular permissions+ canView Boolean @default(true)+ canDownload Boolean @default(false)++ createdAt DateTime @default(now())+ updatedAt DateTime @updatedAt++ @@unique([groupId, itemId])+ @@index([groupId])+}++enum ItemType {+ DATAROOM_DOCUMENT+ DATAROOM_FOLDER+}\ No newline at end of filediff --git a/prisma/schema.prisma b/prisma/schema/schema.prismasimilarity index 84%rename from prisma/schema.prismarename to prisma/schema/schema.prismaindex 6f92e41a..48f1a9c3 100644--- a/prisma/schema.prisma+++ b/prisma/schema/schema.prisma@@ -7,7 +7,7 @@ datasource db {generator client {provider = "prisma-client-js"- previewFeatures = ["relationJoins"]+ previewFeatures = ["relationJoins", "prismaSchemaFolder"]}model Account {@@ -49,7 +49,7 @@ model User {documents Document[]teams UserTeam[]domains Domain[]- conversations Conversation[]+ chats Chat[]contactId String?plan String @default("free")stripeId String? @unique // Stripe subscription / customer ID@@ -58,6 +58,10 @@ model User {endsAt DateTime? // Stripe subscription end daterestrictedTokens RestrictedToken[]++ // conversation+ participatedConversations ConversationParticipant[]+ messages Message[]}model Team {@@ -158,7 +162,7 @@ model Document {links Link[]views View[]versions DocumentVersion[]- conversations Conversation[]+ chats Chat[]folderId String? // Optional Folder ID for documents in foldersfolder Folder? @relation(fields: [folderId], references: [id], onDelete: SetNull)@@ -276,6 +280,10 @@ model Link {metaFavicon String? // This will be the meta favicon of the linkenableCustomMetatag Boolean? @default(false) // Optional give user a option to enable the custom metatag+ // conversation+ conversationsEnabled Boolean @default(false) // Controls if conversations are allowed on this link+ conversations Conversation[]+teamId String?team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)@@ -348,6 +356,11 @@ model View {isArchived Boolean @default(false) // Indicates if the view is archived and not counted in the analytics+ // conversation+ conversationViews ConversationView[]+ messages Message[]+ initialConversations Conversation[] @relation("initialView")+teamId String?team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)@@ -377,6 +390,8 @@ model Viewer {views View[]groups ViewerGroupMembership[]+ participatedConversations ConversationParticipant[]+ messages Message[]createdAt DateTime @default(now())updatedAt DateTime @updatedAt@@ -429,7 +444,7 @@ model SentEmail {@@index([teamId])}-model Conversation {+model Chat {id String @id @default(cuid())threadId String @unique // This is the thread ID from OpenAI Assistant APIuser User @relation(fields: [userId], references: [id], onDelete: Cascade)@@ -462,76 +477,7 @@ model Folder {@@index([parentId])}-model Dataroom {- id String @id @default(cuid())- pId String @unique // This is the generated public ID for the dataroom dr_1234- name String- teamId String- team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)- documents DataroomDocument[]- folders DataroomFolder[]- links Link[]- views View[]- viewers Viewer[]- viewerGroups ViewerGroup[]- brand DataroomBrand?-- createdAt DateTime @default(now())- updatedAt DateTime @updatedAt-- @@index([teamId])-}--model DataroomDocument {- id String @id @default(cuid())- dataroomId String- dataroom Dataroom @relation(fields: [dataroomId], references: [id], onDelete: Cascade)- documentId String- document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)- folderId String?- folder DataroomFolder? @relation(fields: [folderId], references: [id], onDelete: SetNull)- orderIndex Int?-- createdAt DateTime @default(now())- updatedAt DateTime @updatedAt-- @@unique([dataroomId, documentId])- @@index([folderId])- @@index([dataroomId, folderId, orderIndex])-}--model DataroomFolder {- id String @id @default(cuid())- name String- path String // the materialized path to the folder; starts always with "/"- parentId String?- documents DataroomDocument[]- childFolders DataroomFolder[] @relation("SubFolders")- parentFolder DataroomFolder? @relation("SubFolders", fields: [parentId], references: [id], onDelete: SetNull)- dataroomId String- dataroom Dataroom @relation(fields: [dataroomId], references: [id], onDelete: Cascade)- orderIndex Int?- createdAt DateTime @default(now())- updatedAt DateTime @updatedAt-- @@unique([dataroomId, path])- @@index([parentId])- @@index([dataroomId, parentId, orderIndex])-}--model DataroomBrand {- id String @id @default(cuid())- logo String? // This should be a reference to where the file is stored (S3, Google Cloud Storage, etc.)- banner String? // This should be a reference to where the file is stored (S3, Google Cloud Storage, etc.)- brandColor String? // This should be a reference to the brand color- accentColor String? // This should be a reference to the accent color- dataroomId String @unique- dataroom Dataroom @relation(fields: [dataroomId], references: [id], onDelete: Cascade)-- createdAt DateTime @default(now())- updatedAt DateTime @updatedAt-}model Feedback {id String @id @default(cuid())@@ -595,68 +541,7 @@ model AgreementResponse {@@index([viewId])}-model ViewerGroup {- id String @id @default(cuid())- name String- members ViewerGroupMembership[]- domains String[]- links Link[]- accessControls ViewerGroupAccessControls[]- allowAll Boolean @default(false)-- dataroomId String- dataroom Dataroom @relation(fields: [dataroomId], references: [id], onDelete: Cascade)- teamId String- team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)-- views View[]-- createdAt DateTime @default(now())- updatedAt DateTime @updatedAt-- @@index([dataroomId])- @@index([teamId])-}-model ViewerGroupMembership {- id String @id @default(cuid())- viewerId String- viewer Viewer @relation(fields: [viewerId], references: [id], onDelete: Cascade)- groupId String- group ViewerGroup @relation(fields: [groupId], references: [id], onDelete: Cascade)-- createdAt DateTime @default(now())- updatedAt DateTime @updatedAt-- @@unique([viewerId, groupId])- @@index([viewerId])- @@index([groupId])-}--model ViewerGroupAccessControls {- id String @id @default(cuid())- groupId String- group ViewerGroup @relation(fields: [groupId], references: [id], onDelete: Cascade)-- // Access control for items (documents or dataroom items)- itemId String // This can be a document ID or a dataroom item ID- itemType ItemType // Enum: DATAROOM_DOCUMENT, DATAROOM_FOLDER-- // Granular permissions- canView Boolean @default(true)- canDownload Boolean @default(false)-- createdAt DateTime @default(now())- updatedAt DateTime @updatedAt-- @@unique([groupId, itemId])- @@index([groupId])-}--enum ItemType {- DATAROOM_DOCUMENT- DATAROOM_FOLDER-}model IncomingWebhook {id String @id @default(cuid())@@ -771,4 +656,4 @@ model CustomFieldResponse {updatedAt DateTime @updatedAt@@index([viewId])-}+}\ No newline at end of file