- Inject umbral_name into shared_fields for umbral contacts (always visible) - Show @umbralname subtitle in detail panel header - Add preferred_name to panel fields with synced label for umbral contacts - Add Link button on standard contacts to tie to umbral user via connection request - Migration 046: person_id FK on connection_requests with index - Validate person_id ownership on send, re-validate + convert on accept Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
37 lines
1.5 KiB
Python
37 lines
1.5 KiB
Python
from sqlalchemy import String, Integer, ForeignKey, CheckConstraint, func
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from datetime import datetime
|
|
from typing import Optional, TYPE_CHECKING
|
|
from app.database import Base
|
|
|
|
if TYPE_CHECKING:
|
|
from app.models.user import User
|
|
|
|
|
|
class ConnectionRequest(Base):
|
|
__tablename__ = "connection_requests"
|
|
__table_args__ = (
|
|
CheckConstraint(
|
|
"status IN ('pending', 'accepted', 'rejected', 'cancelled')",
|
|
name="ck_connection_requests_status",
|
|
),
|
|
)
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, index=True)
|
|
sender_id: Mapped[int] = mapped_column(
|
|
Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False
|
|
)
|
|
receiver_id: Mapped[int] = mapped_column(
|
|
Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False
|
|
)
|
|
status: Mapped[str] = mapped_column(String(20), nullable=False, server_default="pending")
|
|
created_at: Mapped[datetime] = mapped_column(default=func.now(), server_default=func.now())
|
|
resolved_at: Mapped[Optional[datetime]] = mapped_column(nullable=True, default=None)
|
|
person_id: Mapped[Optional[int]] = mapped_column(
|
|
Integer, ForeignKey("people.id", ondelete="SET NULL"), nullable=True
|
|
)
|
|
|
|
# Relationships with explicit foreign_keys to disambiguate
|
|
sender: Mapped["User"] = relationship(foreign_keys=[sender_id], lazy="selectin")
|
|
receiver: Mapped["User"] = relationship(foreign_keys=[receiver_id], lazy="selectin")
|