schema.prisma•8.7 kB
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
generator client {
provider = "prisma-client-js"
output = "../src/generated/prisma"
previewFeatures = ["postgresqlExtensions", "interactiveTransactions"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
extensions = [vector]
}
model Document {
id String @id @default(uuid())
url String
title String
content String @db.Text
metadata Json // { package: string, version: string, type: string, tags: string[] }
crawlDate DateTime @map("crawl_date")
level Int
parentDocument Document? @relation("DocumentToDocument", fields: [parentDocumentId], references: [id], onDelete: SetNull)
parentDocumentId String? @map("parent_document_id")
childDocuments Document[] @relation("DocumentToDocument")
chunks Chunk[]
job Job? @relation(fields: [jobId], references: [id], onDelete: SetNull)
jobId String? @map("job_id")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
// New relation to package documentation mapping
packageDocMappings PackageDocumentationMapping[]
@@index([url])
@@index([title])
@@index([crawlDate])
@@map("documents")
}
model Chunk {
id String @id @default(uuid())
document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
documentId String @map("document_id")
content String @db.Text
embedding Unsupported("vector(1536)") @map("embedding")
metadata Json // { title: string, order: number, type: string }
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@map("chunks")
}
enum JobStatus {
pending
running
completed
failed
cancelled // New status for cancelled jobs
paused // New status for paused jobs
}
enum JobType {
crawl
process
delete
}
// Enhanced stage tracking for jobs
enum JobStage {
initializing
crawling
processing
embedding
finalizing
cleanup
}
model Job {
id String @id @default(uuid())
url String
status JobStatus @default(pending)
type JobType @default(crawl)
stage JobStage? // Current stage of the job
progress Float @default(0)
startDate DateTime @map("start_date")
endDate DateTime? @map("end_date")
// Error tracking
error String? @db.Text
errorCount Int @default(0) @map("error_count") // Count of errors encountered
lastError DateTime? @map("last_error") // Timestamp of last error
// Enhanced stats tracking
stats Json @default("{ \"pagesProcessed\": 0, \"pagesSkipped\": 0, \"totalChunks\": 0 }")
// New detailed stats fields
itemsTotal Int @default(0) @map("items_total") // Total items to process
itemsProcessed Int @default(0) @map("items_processed") // Items successfully processed
itemsFailed Int @default(0) @map("items_failed") // Items that failed processing
itemsSkipped Int @default(0) @map("items_skipped") // Items intentionally skipped
// Estimated completion
estimatedCompletion DateTime? @map("estimated_completion") // Estimated completion time
timeElapsed Int? @map("time_elapsed") // Time elapsed in seconds
timeRemaining Int? @map("time_remaining") // Estimated time remaining in seconds
// Additional fields for documentation crawling
name String? // Friendly name for the documentation source
maxDepth Int? @map("max_depth") // Maximum depth for crawling
tags String[] // Tags associated with this documentation
metadata Json? // Additional metadata about the job
// Control fields
shouldCancel Boolean @default(false) @map("should_cancel") // Flag to signal job cancellation
shouldPause Boolean @default(false) @map("should_pause") // Flag to signal job pause
priority Int @default(1) // Job priority (higher = more important)
// Timestamps
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
lastActivity DateTime @default(now()) @map("last_activity") // Last activity timestamp
documents Document[] // Add relation back to documents generated by this job
@@index([status])
@@index([type])
@@index([stage])
@@index([createdAt])
@@index([priority])
@@map("jobs")
}
// New models for package-to-documentation mapping
// Package model
model Package {
id String @id @default(uuid())
name String @unique // Package name
language String // Programming language (javascript, python, etc.)
description String? @db.Text
repository String? // Repository URL
homepage String? // Homepage URL
popularity Float @default(0) // Popularity score (for ranking)
// Relations
versions PackageVersion[]
docMappings PackageDocumentationMapping[]
// Timestamps
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@index([name])
@@index([language])
@@index([popularity])
@@map("packages")
}
// Package version model
model PackageVersion {
id String @id @default(uuid())
version String // Version string
package Package @relation(fields: [packageId], references: [id], onDelete: Cascade)
packageId String @map("package_id")
releaseDate DateTime? @map("release_date")
isLatest Boolean @default(false) @map("is_latest")
// Relations
docMappings PackageDocumentationMapping[]
// Timestamps
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@unique([packageId, version])
@@index([version])
@@index([isLatest])
@@map("package_versions")
}
// The mapping between packages, versions, and documentation
model PackageDocumentationMapping {
id String @id @default(uuid())
// Relations
package Package @relation(fields: [packageId], references: [id], onDelete: Cascade)
packageId String @map("package_id")
// Version is optional since some docs apply to multiple versions
version PackageVersion? @relation(fields: [versionId], references: [id], onDelete: SetNull)
versionId String? @map("version_id")
document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
documentId String @map("document_id")
// Source information (moved from DocumentationSource model)
sourceName String @map("source_name") // Name of documentation source (e.g., "MDN", "Official Docs")
sourceUrl String? @map("source_url") // Base URL of the documentation source
sourceReliability Float @default(0.8) @map("source_reliability") // How reliable is this source (0-1)
sourceIsOfficial Boolean @default(false) @map("source_is_official") // Whether this is the official documentation
// Ranking information
relevanceScore Float @default(0.5) @map("relevance_score") // How relevant is this doc to the package (0-1)
isApiDoc Boolean @default(false) @map("is_api_doc") // Is this API documentation
isGuide Boolean @default(false) @map("is_guide") // Is this a guide or tutorial
isHomepage Boolean @default(false) @map("is_homepage") // Is this the package homepage
// Timestamps
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@unique([packageId, documentId])
@@index([relevanceScore])
@@index([sourceName])
@@index([sourceIsOfficial])
@@map("package_documentation_mappings")
}
// Cache for frequently requested documentation lookups
model DocumentationCache {
id String @id @default(uuid())
key String @unique // Cache key (usually package or package+version)
data Json // Cached data (document IDs and metadata)
expiresAt DateTime @map("expires_at") // When this cache entry expires
// Timestamps
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@index([key])
@@index([expiresAt])
@@map("documentation_cache")
}