| from sqlalchemy import Column, BigInteger, Integer, Enum, Text, String, TIMESTAMP, ForeignKey, Index |
| from sqlalchemy.sql import func |
| from . import Base # adjust if Base lives elsewhere |
| |
| class Log(Base): |
| __tablename__ = 'logs' |
| __table_args__ = ( |
| Index('user_id', 'user_id'), |
| Index('idx_logs_created', 'created_at'), |
| ) |
| |
| id = Column(BigInteger, primary_key=True, autoincrement=True, comment='日志ID') |
| user_id = Column(Integer, ForeignKey('users.id', ondelete='SET NULL'), comment='用户ID') |
| type = Column(Enum('access', 'error', 'behavior', 'system', |
| name='logs_type_enum'), nullable=False, comment='日志类型') |
| content = Column(Text, nullable=False, comment='日志内容') |
| ip = Column(String(45), nullable=True, comment='IP地址') |
| created_at = Column(TIMESTAMP, server_default=func.current_timestamp(), |
| nullable=True, comment='记录时间') |