cmvr-visual/backend/app/models/accounts.py
zhanghao 88cf14d794 feat: consolidate story studio and editable automatic production
Restructure backend and frontend modules; add story, library, and editor schema migrations.

Support editable automatic production, manual confirmation modes, account and user lifecycle management, compact container scrolling, consistent forms, and per-task result previews.

Update inference and TTS scheduling, deployment guidance, and regression coverage; remove obsolete standalone pages and temporary acceptance artifacts.
2026-11-14 14:07:26 +08:00

44 lines
1.9 KiB
Python

from datetime import datetime
from sqlalchemy import Boolean, ForeignKey, JSON, String, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column
from app.models.base import Base, Timestamp, new_id, utcnow
class User(Base):
__tablename__ = "visual_users"
id: Mapped[str] = mapped_column(String(32), primary_key=True, default=new_id)
username: Mapped[str] = mapped_column(String(64), unique=True)
display_name: Mapped[str] = mapped_column(String(80))
password_hash: Mapped[str] = mapped_column(String(512))
role: Mapped[str] = mapped_column(String(16), default="user")
disabled: Mapped[bool] = mapped_column(Boolean, default=False)
must_change_password: Mapped[bool] = mapped_column(Boolean, default=False)
created_at: Mapped[datetime] = mapped_column(Timestamp, default=utcnow)
class Session(Base):
__tablename__ = "visual_sessions"
token_hash: Mapped[str] = mapped_column(String(64), primary_key=True)
user_id: Mapped[str] = mapped_column(ForeignKey("visual_users.id"), index=True)
csrf_token: Mapped[str] = mapped_column(String(128))
expires_at: Mapped[datetime] = mapped_column(Timestamp, index=True)
created_at: Mapped[datetime] = mapped_column(Timestamp, default=utcnow)
class ApiToken(Base):
__tablename__ = "visual_api_tokens"
__table_args__ = (UniqueConstraint("token_hash"),)
id: Mapped[str] = mapped_column(String(32), primary_key=True, default=new_id)
owner_id: Mapped[str] = mapped_column(String(32), ForeignKey("visual_users.id"), index=True)
name: Mapped[str] = mapped_column(String(128))
token_hash: Mapped[str] = mapped_column(String(64))
scopes: Mapped[list] = mapped_column(JSON, default=list)
expires_at: Mapped[datetime | None] = mapped_column(Timestamp, nullable=True)
revoked_at: Mapped[datetime | None] = mapped_column(Timestamp, nullable=True)
created_at: Mapped[datetime] = mapped_column(Timestamp, default=utcnow)