File size: 2,013 Bytes
67f8819 1ab030e 67f8819 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | """
Task model representing user tasks.
Per @specs/001-auth-api-bridge/data-model.md
"""
from sqlmodel import SQLModel, Field, Relationship
from typing import TYPE_CHECKING, Optional
from datetime import datetime
from uuid import UUID, uuid4
if TYPE_CHECKING:
from models.user import UserTable
class TaskTable(SQLModel, table=True):
"""
Task owned by a user.
Each task belongs to exactly one user. All queries MUST filter by user_id
to ensure data isolation per constitutional principle.
"""
__tablename__ = "tasks"
# Primary key
id: UUID = Field(
default_factory=uuid4,
primary_key=True,
index=True,
description="Unique task identifier"
)
# Foreign key to User
user_id: UUID = Field(
foreign_key="users.id",
index=True,
nullable=False,
description="ID of the user who owns this task"
)
# Task attributes
title: str = Field(
max_length=255,
nullable=False,
description="Short title of the task"
)
description: Optional[str] = Field(
default=None,
max_length=5000,
description="Detailed description of the task (optional)"
)
# Completion status
completed: bool = Field(
default=False,
index=True,
description="Whether the task has been completed"
)
# Priority level
priority: str = Field(
default="medium",
nullable=False,
description="Task priority level: low, medium, or high"
)
# Timestamps
created_at: datetime = Field(
default_factory=datetime.utcnow,
nullable=False,
description="Timestamp when task was created"
)
completed_at: Optional[datetime] = Field(
default=None,
nullable=True,
index=True,
description="Timestamp when task was marked as completed (null until completed)"
)
# Relationships
user: "UserTable" = Relationship(back_populates="tasks")
|