feat: Sprint 1 foundation - FastAPI scaffold, DB schema, auth, seed data, mock WhatsApp, Docker
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
"""Ticket category model with self-referencing parent for sub-categories."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from sqlalchemy import ForeignKey, Integer, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class Category(Base):
|
||||
__tablename__ = "categories"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
type: Mapped[str] = mapped_column(
|
||||
String(20),
|
||||
nullable=False,
|
||||
comment="maintenance, cs, emergency",
|
||||
)
|
||||
name: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||
parent_id: Mapped[int | None] = mapped_column(
|
||||
Integer,
|
||||
ForeignKey("categories.id"),
|
||||
nullable=True,
|
||||
)
|
||||
sla_urgency: Mapped[str | None] = mapped_column(
|
||||
String(10),
|
||||
nullable=True,
|
||||
comment="urgent, high, medium, low",
|
||||
)
|
||||
|
||||
# self-referencing relationship
|
||||
children: Mapped[list[Category]] = relationship("Category", back_populates="parent", cascade="all, delete-orphan")
|
||||
parent: Mapped[Category | None] = relationship("Category", back_populates="children", remote_side="Category.id")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<Category {self.type}:{self.name}>"
|
||||
Reference in New Issue
Block a user