- Add outgoing_links (JSON) and backlinks_count to Document model
- POST /documents/{id}/detect-links — detect [[uuid]] patterns in content
- GET /documents/{id}/backlinks — documents referencing this doc
- GET /documents/{id}/outgoing-links — documents this doc references
- GET /documents/{id}/links — combined incoming + outgoing
- GET /projects/{id}/graph — full project relationship graph
- GET /search/quick — fuzzy search (Quick Switcher Cmd+K)
- GET /projects/{id}/documents/search — project-scoped search
- GET /documents/{id}/export — markdown|json export
- GET /projects/{id}/export — json|zip export
- 27 new tests
45 lines
2.2 KiB
Python
45 lines
2.2 KiB
Python
import uuid
|
|
from datetime import datetime
|
|
from enum import Enum
|
|
|
|
from sqlalchemy import Boolean, DateTime, ForeignKey, String, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.database import Base
|
|
|
|
|
|
def generate_uuid() -> str:
|
|
return str(uuid.uuid4())
|
|
|
|
|
|
class ReasoningType(str, Enum):
|
|
CHAIN = "chain"
|
|
IDEA = "idea"
|
|
CONTEXT = "context"
|
|
REFLECTION = "reflection"
|
|
|
|
|
|
class Document(Base):
|
|
__tablename__ = "documents"
|
|
|
|
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=generate_uuid)
|
|
title: Mapped[str] = mapped_column(String(500), nullable=False)
|
|
content: Mapped[str] = mapped_column(Text, nullable=False, default="")
|
|
project_id: Mapped[str] = mapped_column(String(36), ForeignKey("projects.id", ondelete="CASCADE"), nullable=False)
|
|
folder_id: Mapped[str | None] = mapped_column(String(36), ForeignKey("folders.id", ondelete="SET NULL"), nullable=True)
|
|
path: Mapped[str] = mapped_column(Text, nullable=False)
|
|
is_deleted: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
|
deleted_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
|
deleted_by: Mapped[str | None] = mapped_column(String(36), nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
|
|
# Phase 2: Reasoning fields
|
|
reasoning_type: Mapped[str | None] = mapped_column(String(20), nullable=True)
|
|
confidence: Mapped[str | None] = mapped_column(String(10), nullable=True) # Store as string to handle JSON serialization
|
|
reasoning_steps: Mapped[str | None] = mapped_column(Text, nullable=True) # JSON array as text
|
|
model_source: Mapped[str | None] = mapped_column(String(100), nullable=True)
|
|
tiptap_content: Mapped[str | None] = mapped_column(Text, nullable=True) # JSON object as text
|
|
# Phase 3: Link tracking
|
|
outgoing_links: Mapped[str] = mapped_column(Text, nullable=False, default="[]") # JSON array of document IDs
|
|
backlinks_count: Mapped[int] = mapped_column(default=0, nullable=False) # Cached count of incoming links
|