Enables multi-user project collaboration mirroring the shared calendar pattern. Includes ProjectMember model with permission levels, task assignment with auto-membership, optimistic locking, field allowlist for assignees, disconnect cascade, delta polling for projects and calendars, and full frontend integration with share sheet, assignment picker, permission gating, and notification handling. Migrations: 057 (indexes + version + comment user_id), 058 (project_members), 059 (project_task_assignments) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
31 lines
1.3 KiB
Python
31 lines
1.3 KiB
Python
from sqlalchemy import DateTime, Integer, ForeignKey, UniqueConstraint, func
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from datetime import datetime
|
|
from app.database import Base
|
|
|
|
|
|
class ProjectTaskAssignment(Base):
|
|
__tablename__ = "project_task_assignments"
|
|
__table_args__ = (
|
|
UniqueConstraint("task_id", "user_id", name="uq_task_assignments_task_user"),
|
|
)
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, index=True)
|
|
task_id: Mapped[int] = mapped_column(
|
|
Integer, ForeignKey("project_tasks.id", ondelete="CASCADE"), nullable=False, index=True
|
|
)
|
|
user_id: Mapped[int] = mapped_column(
|
|
Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True
|
|
)
|
|
assigned_by: Mapped[int] = mapped_column(
|
|
Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False
|
|
)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime, default=func.now(), server_default=func.now()
|
|
)
|
|
|
|
# Relationships — lazy="raise" to prevent N+1
|
|
task: Mapped["ProjectTask"] = relationship(back_populates="assignments", lazy="raise")
|
|
user: Mapped["User"] = relationship(foreign_keys=[user_id], lazy="raise")
|
|
assigner: Mapped["User"] = relationship(foreign_keys=[assigned_by], lazy="raise")
|