Files
CosScene/server/app/models/audit_log.py
T
2026-05-09 16:40:29 +08:00

28 lines
979 B
Python

from datetime import datetime
from sqlalchemy import DateTime, ForeignKey, Integer, String, Text, func
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.db.base import Base
class AuditLog(Base):
__tablename__ = "audit_logs"
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
operator_id: Mapped[int] = mapped_column(
Integer, ForeignKey("users.id"), nullable=False
)
action: Mapped[str] = mapped_column(String(100), nullable=False, index=True)
target_type: Mapped[str] = mapped_column(String(50), nullable=False)
target_id: Mapped[int | None] = mapped_column(Integer)
detail: Mapped[str | None] = mapped_column(Text)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now()
)
operator = relationship("User", lazy="selectin")
def __repr__(self) -> str:
return f"<AuditLog {self.id} {self.action} by={self.operator_id}>"