"""User 用户模型。""" from sqlalchemy import ForeignKey, Integer, String, Text from sqlalchemy.orm import Mapped, mapped_column, relationship from app.models.base import Base, TimestampMixin, UUIDPrimaryKeyMixin class User(UUIDPrimaryKeyMixin, TimestampMixin, Base): """用户模型。 技术审查 §2.2:users 表。 """ __tablename__ = "users" username: Mapped[str] = mapped_column( String(64), unique=True, nullable=False, index=True, comment="用户名", ) email: Mapped[str] = mapped_column( String(255), unique=True, nullable=False, index=True, comment="邮箱", ) password_hash: Mapped[str] = mapped_column( String(255), nullable=False, comment="Argon2id 密码哈希", ) status: Mapped[str] = mapped_column( String(16), default="active", nullable=False, comment="状态 (active/disabled)", ) plan_id: Mapped[str] = mapped_column( String(32), ForeignKey("plans.id"), nullable=False, comment="套餐 ID", ) storage_used: Mapped[int] = mapped_column( Integer, default=0, nullable=False, comment="已用存储 (字节)", ) # 关系 plan = relationship("Plan", back_populates="users", lazy="selectin") knowledge_bases = relationship("KnowledgeBase", back_populates="user", lazy="selectin") documents = relationship("Document", back_populates="user", lazy="selectin") def __repr__(self) -> str: return f""