27 lines
1.3 KiB
Python
27 lines
1.3 KiB
Python
|
|
"""
|
||
|
|
操作审计日志模型
|
||
|
|
"""
|
||
|
|
import uuid
|
||
|
|
from sqlalchemy import Column, String, Text, DateTime, JSON, func
|
||
|
|
from sqlalchemy.dialects.mysql import CHAR
|
||
|
|
from app.core.database import Base
|
||
|
|
|
||
|
|
|
||
|
|
class AuditLog(Base):
|
||
|
|
__tablename__ = "audit_logs"
|
||
|
|
|
||
|
|
id = Column(CHAR(36), primary_key=True, default=lambda: str(uuid.uuid4()), comment="日志ID")
|
||
|
|
user_id = Column(CHAR(36), nullable=False, index=True, comment="操作用户ID")
|
||
|
|
username = Column(String(100), nullable=False, comment="操作用户名")
|
||
|
|
action = Column(String(50), nullable=False, index=True, comment="操作类型: CREATE/UPDATE/DELETE/EXECUTE/LOGIN")
|
||
|
|
resource_type = Column(String(100), nullable=False, comment="资源类型: agent/workflow/user/permission/...")
|
||
|
|
resource_id = Column(String(100), nullable=True, comment="资源ID")
|
||
|
|
resource_name = Column(String(255), nullable=True, comment="资源名称")
|
||
|
|
detail = Column(JSON, nullable=True, comment="操作详情")
|
||
|
|
ip_address = Column(String(45), nullable=True, comment="客户端IP")
|
||
|
|
status = Column(String(20), nullable=False, default="success", comment="操作状态: success/failure")
|
||
|
|
created_at = Column(DateTime, default=func.now(), index=True, comment="操作时间")
|
||
|
|
|
||
|
|
def __repr__(self):
|
||
|
|
return f"<AuditLog(id={self.id}, user={self.username}, action={self.action}, resource={self.resource_type})>"
|