from datetime import datetime, timezone from typing import Optional from sqlalchemy import JSON, DateTime, Integer, String, Text from sqlalchemy.orm import Mapped, mapped_column from app.db import Base class KnowledgeBaseDocument(Base): __tablename__ = "knowledge_base_documents" id: Mapped[str] = mapped_column(String(64), primary_key=True) knowledge_base_id: Mapped[str] = mapped_column(String(64), nullable=False, index=True) tenant_id: Mapped[str] = mapped_column(String(64), nullable=False, index=True) file_name: Mapped[str] = mapped_column(String(255), nullable=False) mime_type: Mapped[Optional[str]] = mapped_column(String(120), nullable=True) file_size: Mapped[int] = mapped_column(Integer, default=0) status: Mapped[str] = mapped_column(String(32), default="indexed") source_type: Mapped[Optional[str]] = mapped_column(String(64), nullable=True, index=True) authority: Mapped[Optional[str]] = mapped_column(String(255), nullable=True) effective_date: Mapped[Optional[str]] = mapped_column(String(128), nullable=True) region: Mapped[Optional[str]] = mapped_column(String(120), nullable=True, index=True) tags_json: Mapped[Optional[list[str]]] = mapped_column(JSON, nullable=True) content_excerpt: Mapped[Optional[str]] = mapped_column(Text, nullable=True) error_message: Mapped[Optional[str]] = mapped_column(Text, nullable=True) created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=lambda: datetime.now(timezone.utc), index=True)