Skip to content

Commit 5732945

Browse files
committed
feat: Add Document model and database schema for artifacts support
1 parent 588d2b5 commit 5732945

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-- CreateEnum
2+
CREATE TYPE "ArtifactKind" AS ENUM ('text', 'code', 'custom');
3+
4+
-- CreateTable
5+
CREATE TABLE "Document" (
6+
"id" TEXT NOT NULL,
7+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
8+
"updatedAt" TIMESTAMP(3) NOT NULL,
9+
"title" TEXT NOT NULL,
10+
"content" TEXT,
11+
"kind" "ArtifactKind" NOT NULL DEFAULT 'text',
12+
"userId" TEXT NOT NULL,
13+
"chatId" TEXT,
14+
15+
CONSTRAINT "Document_pkey" PRIMARY KEY ("id")
16+
);
17+
18+
-- AddForeignKey
19+
ALTER TABLE "Document" ADD CONSTRAINT "Document_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
20+
21+
-- AddForeignKey
22+
ALTER TABLE "Document" ADD CONSTRAINT "Document_chatId_fkey" FOREIGN KEY ("chatId") REFERENCES "Chat"("id") ON DELETE SET NULL ON UPDATE CASCADE;

prisma/schema.prisma

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ model User {
5757
videos Video[]
5858
userFeatures UserFeature[]
5959
workbenches Workbench[]
60+
documents Document[]
6061
}
6162

6263
enum UserRole {
@@ -92,6 +93,7 @@ model Chat {
9293
messages Message[]
9394
stream Stream[]
9495
workbench Workbench? @relation(fields: [workbenchId], references: [id], onDelete: SetNull)
96+
documents Document[]
9597
}
9698

9799
model Message {
@@ -190,4 +192,23 @@ model Tool {
190192
toolkit Toolkit @relation(fields: [toolkitId], references: [id], onDelete: Cascade)
191193
192194
@@id([id, toolkitId])
195+
}
196+
197+
enum ArtifactKind {
198+
text
199+
code
200+
custom
201+
}
202+
203+
model Document {
204+
id String @id @default(uuid())
205+
createdAt DateTime @default(now())
206+
updatedAt DateTime @updatedAt
207+
title String
208+
content String? @db.Text
209+
kind ArtifactKind @default(text)
210+
userId String
211+
chatId String? // Optional association with a chat
212+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
213+
chat Chat? @relation(fields: [chatId], references: [id], onDelete: SetNull)
193214
}

0 commit comments

Comments
 (0)