File size: 2,104 Bytes
939c0c0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | """
Document model — stores metadata for every uploaded file.
The actual binary is stored on the filesystem (uploads/).
Embeddings/chunks live in Qdrant.
"""
from __future__ import annotations
import uuid
from datetime import datetime
from sqlalchemy import Boolean, DateTime, ForeignKey, Integer, String, Text, func
from sqlalchemy.orm import Mapped, mapped_column
from app.core.database import Base
class Document(Base):
__tablename__ = "documents"
id: Mapped[str] = mapped_column(
String(36), primary_key=True, default=lambda: str(uuid.uuid4())
)
# Ownership
tenant_id: Mapped[str] = mapped_column(
String(36), ForeignKey("tenants.id"), nullable=False, index=True
)
uploaded_by: Mapped[str] = mapped_column(
String(36), ForeignKey("users.id"), nullable=False
)
# File metadata
filename: Mapped[str] = mapped_column(String(512), nullable=False)
original_name: Mapped[str] = mapped_column(String(512), nullable=False)
file_path: Mapped[str] = mapped_column(String(1024), nullable=False)
file_size_bytes: Mapped[int] = mapped_column(Integer, default=0)
mime_type: Mapped[str] = mapped_column(String(100), default="application/pdf")
# Classification
doc_type: Mapped[str] = mapped_column(
String(50), default="general"
) # general | hr | finance | legal | technical
# Processing status
status: Mapped[str] = mapped_column(
String(30), default="pending"
) # pending | processing | ready | failed
error_message: Mapped[str | None] = mapped_column(Text, nullable=True)
chunk_count: Mapped[int] = mapped_column(Integer, default=0)
page_count: Mapped[int] = mapped_column(Integer, default=0)
# Timestamps
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), index=True
)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
)
def __repr__(self) -> str:
return f"<Document {self.filename} [{self.status}]>"
|