nex_docus/backend/app/models/log.py

29 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

"""
操作日志模型
"""
from sqlalchemy import Column, BigInteger, String, Integer, DateTime, SmallInteger, Text
from sqlalchemy.sql import func
from app.core.database import Base
class OperationLog(Base):
"""操作日志表模型"""
__tablename__ = "operation_logs"
id = Column(BigInteger, primary_key=True, autoincrement=True, comment="日志ID")
user_id = Column(BigInteger, index=True, comment="操作用户ID")
username = Column(String(50), comment="用户名")
operation_type = Column(String(50), nullable=False, comment="操作类型")
resource_type = Column(String(50), nullable=False, index=True, comment="资源类型")
resource_id = Column(BigInteger, index=True, comment="资源ID")
detail = Column(Text, comment="操作详情JSON")
ip_address = Column(String(50), comment="IP地址")
user_agent = Column(String(500), comment="用户代理")
status = Column(SmallInteger, default=1, comment="状态0-失败 1-成功")
error_message = Column(Text, comment="错误信息")
created_at = Column(DateTime, server_default=func.now(), index=True, comment="操作时间")
def __repr__(self):
return f"<OperationLog(id={self.id}, operation_type='{self.operation_type}')>"