Files
amb_rag/backend/app/models/user.py
T
2026-09-02 11:19:49 +08:00

68 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""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.2users 表。
"""
__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)",
)
role: Mapped[str] = mapped_column(
String(16),
default="customer",
nullable=False,
comment="角色 (internal=内部员工 / customer=客户)",
)
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"<User {self.username!r}>"