- 复制来源: /home/yueli/track @ 192c8ee (feature/ai-audit-update) - 组织隔离目标: LICA - 端口规划: 前端 8030 / 后端 8031 / 数据库 8032 - 已排除 deploy.sh、deploy_full.sh、docker-compose.prod.yml(IRIS 生产发布脚本) - 已排除工作区未提交改动,取干净的 192c8ee 状态
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
"""任务操作日志模型"""
|
||
import uuid
|
||
from datetime import datetime
|
||
from sqlalchemy import String, DateTime, ForeignKey, Text
|
||
from sqlalchemy.dialects.postgresql import UUID
|
||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||
|
||
from app.models.base import Base
|
||
from app.core.time_utils import get_beijing_time
|
||
|
||
|
||
class TaskLog(Base):
|
||
__tablename__ = "task_logs"
|
||
|
||
id: Mapped[uuid.UUID] = mapped_column(
|
||
UUID(as_uuid=True), primary_key=True, default=uuid.uuid4,
|
||
)
|
||
|
||
# ---- 物理外键(关联本库 tasks) ----
|
||
task_id: Mapped[uuid.UUID] = mapped_column(
|
||
UUID(as_uuid=True), ForeignKey("tasks.id"), nullable=False, index=True, comment="所属任务ID",
|
||
)
|
||
|
||
# ---- 逻辑外键(关联老系统用户表,仅存储 ID,无物理约束) ----
|
||
operator_id: Mapped[str | None] = mapped_column(
|
||
String(64), nullable=True, comment="操作人ID(逻辑外键→老系统)",
|
||
)
|
||
|
||
action_type: Mapped[str] = mapped_column(
|
||
String(50), nullable=False, comment="操作类型",
|
||
)
|
||
|
||
remark: Mapped[str | None] = mapped_column(
|
||
Text, nullable=True, comment="备注",
|
||
)
|
||
|
||
created_at: Mapped[datetime] = mapped_column(
|
||
DateTime(timezone=True), default=get_beijing_time, comment="创建时间",
|
||
)
|
||
|
||
# ---- 关系 ----
|
||
task: Mapped["Task"] = relationship("Task", lazy="selectin")
|
||
|
||
def __repr__(self) -> str:
|
||
return f"<TaskLog {self.action_type} @ {self.created_at}>"
|