from __future__ import annotations from datetime import datetime from sqlalchemy import ForeignKey, String, UniqueConstraint from sqlalchemy.orm import Mapped, mapped_column from app.models.base import Base, UTCDateTime, utcnow # Fixed palette; the frontend maps these keys to colors that fit the dark theme PROJECT_COLORS = ("blue", "teal", "green", "amber", "orange", "red", "pink", "violet") class Project(Base): __tablename__ = "projects" __table_args__ = (UniqueConstraint("user_id", "name_key", name="uq_projects_user_name"),) id: Mapped[int] = mapped_column(primary_key=True) user_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE")) name: Mapped[str] = mapped_column(String(100)) # Case-folded name, so "Work" and "work" count as the same project name_key: Mapped[str] = mapped_column(String(100)) color: Mapped[str] = mapped_column(String(16), default="blue") created_at: Mapped[datetime] = mapped_column(UTCDateTime, default=utcnow) updated_at: Mapped[datetime] = mapped_column(UTCDateTime, default=utcnow)