blob: ac8cf1cb9ea1d84a5258a958485497a691aef04e [file] [log] [blame]
TRM-codingc4b4f3d2025-06-18 19:02:46 +08001from sqlalchemy import Column, BigInteger, Integer, Enum, Text, String, TIMESTAMP, ForeignKey, Index
2from sqlalchemy.sql import func
3from . import Base # adjust if Base lives elsewhere
4
5class Log(Base):
6 __tablename__ = 'logs'
7 __table_args__ = (
8 Index('user_id', 'user_id'),
9 Index('idx_logs_created', 'created_at'),
10 )
11
12 id = Column(BigInteger, primary_key=True, autoincrement=True, comment='日志ID')
13 user_id = Column(Integer, ForeignKey('users.id', ondelete='SET NULL'), comment='用户ID')
14 type = Column(Enum('access', 'error', 'behavior', 'system',
15 name='logs_type_enum'), nullable=False, comment='日志类型')
16 content = Column(Text, nullable=False, comment='日志内容')
17 ip = Column(String(45), nullable=True, comment='IP地址')
18 created_at = Column(TIMESTAMP, server_default=func.current_timestamp(),
19 nullable=True, comment='记录时间')