from __future__ import annotations import uuid from datetime import datetime from typing import Optional from sqlalchemy import String, Text, BigInteger, DateTime, func from sqlalchemy.orm import Mapped, mapped_column from app.core.database import Base class User(Base): __tablename__ = "users" id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid.uuid4())) email: Mapped[str] = mapped_column(String(255), unique=True, nullable=False, index=True) password_hash: Mapped[str] = mapped_column(String(255), nullable=False) status: Mapped[str] = mapped_column(String(20), default="active") created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now()) updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now()) # sub2api 用户体系映射 sub2api_user_id: Mapped[Optional[int]] = mapped_column(BigInteger, nullable=True, index=True) sub2api_refresh_token_enc: Mapped[Optional[str]] = mapped_column(Text, nullable=True) sub2api_access_token: Mapped[Optional[str]] = mapped_column(Text, nullable=True) sub2api_access_expires_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)