from datetime import datetime from sqlalchemy import BigInteger, DateTime, ForeignKey, Integer, String, Text, func from sqlalchemy.orm import Mapped, mapped_column from app.db.base import Base class SchemeVersionRecord(Base): __tablename__ = "scheme_versions" id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True) scheme_version_id: Mapped[str] = mapped_column(String(32), unique=True, index=True, nullable=False) scheme_id: Mapped[str] = mapped_column( String(32), ForeignKey("schemes.scheme_id", ondelete="CASCADE"), nullable=False, index=True, ) version_number: Mapped[int] = mapped_column(Integer, nullable=False) status: Mapped[str] = mapped_column(String(32), nullable=False, default="draft") normalized_storage_path: Mapped[str] = mapped_column(Text, nullable=False) normalized_elements_count: Mapped[int] = mapped_column(Integer, nullable=False) normalized_seats_count: Mapped[int] = mapped_column(Integer, nullable=False) normalized_groups_count: Mapped[int] = mapped_column(Integer, nullable=False) normalized_sectors_count: Mapped[int] = mapped_column(Integer, nullable=False) display_svg_storage_path: Mapped[str | None] = mapped_column(Text, nullable=True) display_svg_status: Mapped[str] = mapped_column(String(32), nullable=False, default="pending") display_svg_generated_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True) created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), nullable=False, server_default=func.now(), )