Files
amb_rag/backend/app/models/access_log.py
T
2026-09-01 12:24:43 +08:00

57 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""AccessLog 访问日志模型。"""
from sqlalchemy import ForeignKey, Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.models.base import Base, TimestampMixin, UUIDPrimaryKeyMixin
class AccessLog(UUIDPrimaryKeyMixin, TimestampMixin, Base):
"""访问日志模型。
技术审查 §2.2access_logs 表。
"""
__tablename__ = "access_logs"
knowledge_base_id: Mapped[str] = mapped_column(
String(32),
ForeignKey("knowledge_bases.id"),
nullable=False,
index=True,
comment="知识库 ID",
)
document_id: Mapped[str | None] = mapped_column(
String(32),
ForeignKey("documents.id"),
nullable=True,
comment="文档 ID (可选)",
)
path: Mapped[str] = mapped_column(
String(1024),
nullable=False,
comment="请求路径",
)
accessed_at: Mapped[str] = mapped_column(
String(32),
nullable=False,
comment="访问时间 (ISO8601)",
)
user_agent: Mapped[str | None] = mapped_column(
Text,
nullable=True,
comment="User-Agent",
)
request_type: Mapped[str | None] = mapped_column(
String(32),
nullable=True,
comment="请求类型 (html/md/txt/json/search)",
)
# 关系
knowledge_base = relationship("KnowledgeBase", back_populates="access_logs", lazy="selectin")
document = relationship("Document", back_populates="access_logs", lazy="selectin")
def __repr__(self) -> str:
return f"<AccessLog path={self.path!r} at={self.accessed_at!r}>"