"""Log entry model — stored in PostgreSQL.""" import uuid from datetime import datetime, timezone from sqlalchemy import DateTime, Index, Integer, String, Text from sqlalchemy.dialects.postgresql import JSONB from sqlalchemy.orm import Mapped, mapped_column from app.database import Base class LogEntry(Base): __tablename__ = "log_entries" id: Mapped[str] = mapped_column( String(36), primary_key=True, default=lambda: str(uuid.uuid4()) ) project_id: Mapped[str] = mapped_column(String(36), nullable=False, index=True) project_name: Mapped[str] = mapped_column(String(128), nullable=False, index=True) timestamp: Mapped[datetime] = mapped_column( DateTime(timezone=True), nullable=False, index=True, default=lambda: datetime.now(timezone.utc), ) level: Mapped[str] = mapped_column(String(16), nullable=False, index=True) logger: Mapped[str] = mapped_column(String(128), default="root") message: Mapped[str] = mapped_column(Text, nullable=False) module: Mapped[str | None] = mapped_column(String(256), nullable=True) function: Mapped[str | None] = mapped_column(String(128), nullable=True) line_no: Mapped[int | None] = mapped_column(Integer, nullable=True) trace_id: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True) exception: Mapped[str | None] = mapped_column(Text, nullable=True) extra: Mapped[dict] = mapped_column(JSONB, default=dict) __table_args__ = ( Index("ix_log_entries_project_time", "project_id", timestamp.desc()), )