TRM-coding | c4b4f3d | 2025-06-18 19:02:46 +0800 | [diff] [blame] | 1 | from sqlalchemy import Column, BigInteger, Integer, Enum, Text, String, TIMESTAMP, ForeignKey, Index |
| 2 | from sqlalchemy.sql import func |
| 3 | from . import Base # adjust if Base lives elsewhere |
| 4 | |
| 5 | class 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='记录时间') |