第二步
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
"""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.2:access_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}>"
|
||||
Reference in New Issue
Block a user