feat(knowledge): add database schema for Knowledge Module
Implements KNOW-001 - KnowledgeEntry, Version, Link, Tag, Embedding models - Full indexes and constraints - Seed data for testing
This commit is contained in:
@@ -96,6 +96,18 @@ enum AgentStatus {
|
||||
TERMINATED
|
||||
}
|
||||
|
||||
enum EntryStatus {
|
||||
DRAFT
|
||||
PUBLISHED
|
||||
ARCHIVED
|
||||
}
|
||||
|
||||
enum Visibility {
|
||||
PRIVATE
|
||||
WORKSPACE
|
||||
PUBLIC
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// MODELS
|
||||
// ============================================
|
||||
@@ -138,19 +150,21 @@ model Workspace {
|
||||
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz
|
||||
|
||||
// Relations
|
||||
owner User @relation("WorkspaceOwner", fields: [ownerId], references: [id], onDelete: Cascade)
|
||||
members WorkspaceMember[]
|
||||
tasks Task[]
|
||||
events Event[]
|
||||
projects Project[]
|
||||
activityLogs ActivityLog[]
|
||||
memoryEmbeddings MemoryEmbedding[]
|
||||
domains Domain[]
|
||||
ideas Idea[]
|
||||
relationships Relationship[]
|
||||
agents Agent[]
|
||||
agentSessions AgentSession[]
|
||||
userLayouts UserLayout[]
|
||||
owner User @relation("WorkspaceOwner", fields: [ownerId], references: [id], onDelete: Cascade)
|
||||
members WorkspaceMember[]
|
||||
tasks Task[]
|
||||
events Event[]
|
||||
projects Project[]
|
||||
activityLogs ActivityLog[]
|
||||
memoryEmbeddings MemoryEmbedding[]
|
||||
domains Domain[]
|
||||
ideas Idea[]
|
||||
relationships Relationship[]
|
||||
agents Agent[]
|
||||
agentSessions AgentSession[]
|
||||
userLayouts UserLayout[]
|
||||
knowledgeEntries KnowledgeEntry[]
|
||||
knowledgeTags KnowledgeTag[]
|
||||
|
||||
@@index([ownerId])
|
||||
@@map("workspaces")
|
||||
@@ -605,3 +619,131 @@ model Verification {
|
||||
@@index([identifier])
|
||||
@@map("verifications")
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// KNOWLEDGE MODULE
|
||||
// ============================================
|
||||
|
||||
model KnowledgeEntry {
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
workspaceId String @map("workspace_id") @db.Uuid
|
||||
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
|
||||
|
||||
// Identity
|
||||
slug String
|
||||
title String
|
||||
|
||||
// Content
|
||||
content String @db.Text
|
||||
contentHtml String? @map("content_html") @db.Text
|
||||
summary String?
|
||||
|
||||
// Status
|
||||
status EntryStatus @default(DRAFT)
|
||||
visibility Visibility @default(PRIVATE)
|
||||
|
||||
// Audit
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz
|
||||
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz
|
||||
createdBy String @map("created_by") @db.Uuid
|
||||
updatedBy String @map("updated_by") @db.Uuid
|
||||
|
||||
// Relations
|
||||
tags KnowledgeEntryTag[]
|
||||
outgoingLinks KnowledgeLink[] @relation("SourceEntry")
|
||||
incomingLinks KnowledgeLink[] @relation("TargetEntry")
|
||||
versions KnowledgeEntryVersion[]
|
||||
embedding KnowledgeEmbedding?
|
||||
|
||||
@@unique([workspaceId, slug])
|
||||
@@index([workspaceId, status])
|
||||
@@index([workspaceId, updatedAt])
|
||||
@@index([createdBy])
|
||||
@@index([updatedBy])
|
||||
@@map("knowledge_entries")
|
||||
}
|
||||
|
||||
model KnowledgeEntryVersion {
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
entryId String @map("entry_id") @db.Uuid
|
||||
entry KnowledgeEntry @relation(fields: [entryId], references: [id], onDelete: Cascade)
|
||||
|
||||
version Int
|
||||
title String
|
||||
content String @db.Text
|
||||
summary String?
|
||||
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz
|
||||
createdBy String @map("created_by") @db.Uuid
|
||||
changeNote String? @map("change_note")
|
||||
|
||||
@@unique([entryId, version])
|
||||
@@index([entryId, version])
|
||||
@@map("knowledge_entry_versions")
|
||||
}
|
||||
|
||||
model KnowledgeLink {
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
|
||||
sourceId String @map("source_id") @db.Uuid
|
||||
source KnowledgeEntry @relation("SourceEntry", fields: [sourceId], references: [id], onDelete: Cascade)
|
||||
|
||||
targetId String @map("target_id") @db.Uuid
|
||||
target KnowledgeEntry @relation("TargetEntry", fields: [targetId], references: [id], onDelete: Cascade)
|
||||
|
||||
// Link metadata
|
||||
linkText String @map("link_text")
|
||||
context String?
|
||||
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz
|
||||
|
||||
@@unique([sourceId, targetId])
|
||||
@@index([sourceId])
|
||||
@@index([targetId])
|
||||
@@map("knowledge_links")
|
||||
}
|
||||
|
||||
model KnowledgeTag {
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
workspaceId String @map("workspace_id") @db.Uuid
|
||||
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
|
||||
|
||||
name String
|
||||
slug String
|
||||
color String?
|
||||
description String?
|
||||
|
||||
entries KnowledgeEntryTag[]
|
||||
|
||||
@@unique([workspaceId, slug])
|
||||
@@index([workspaceId])
|
||||
@@map("knowledge_tags")
|
||||
}
|
||||
|
||||
model KnowledgeEntryTag {
|
||||
entryId String @map("entry_id") @db.Uuid
|
||||
entry KnowledgeEntry @relation(fields: [entryId], references: [id], onDelete: Cascade)
|
||||
|
||||
tagId String @map("tag_id") @db.Uuid
|
||||
tag KnowledgeTag @relation(fields: [tagId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@id([entryId, tagId])
|
||||
@@index([entryId])
|
||||
@@index([tagId])
|
||||
@@map("knowledge_entry_tags")
|
||||
}
|
||||
|
||||
model KnowledgeEmbedding {
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
entryId String @unique @map("entry_id") @db.Uuid
|
||||
entry KnowledgeEntry @relation(fields: [entryId], references: [id], onDelete: Cascade)
|
||||
|
||||
embedding Unsupported("vector(1536)")
|
||||
model String
|
||||
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz
|
||||
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz
|
||||
|
||||
@@index([entryId])
|
||||
@@map("knowledge_embeddings")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user