# model/user.py # 用户表:用于 JWT 登录认证与 RBAC 角色控制(建表语句中缺失,此处补充) from datetime import datetime from sqlalchemy import Column, Integer, String, DateTime, ForeignKey from database import Base class User(Base): __tablename__ = "user" user_id = Column(Integer, primary_key=True, autoincrement=True) username = Column(String(50), nullable=False, unique=True, comment="登录名") password_hash = Column(String(200), nullable=False, comment="密码哈希(PBKDF2)") role = Column(String(20), nullable=False, comment="角色: admin/teacher/student") # 关联业务身份:student 角色账号绑定学号,teacher 角色账号绑定教师工号(便于资源归属校验) stu_id = Column(Integer, ForeignKey("student.stu_id"), nullable=True, comment="学生角色的学号") teacher_id = Column(Integer, ForeignKey("teacher.teacher_id"), nullable=True, comment="教师角色的工号") is_deleted = Column(Integer, default=0, nullable=False, comment="逻辑删除: 0正常 1删除") create_time = Column(DateTime, default=datetime.now, comment="创建时间") def __repr__(self): return f""