Migrations 047-051: - 047: Add is_shared to calendars - 048: Create calendar_members table (permissions, status, constraints) - 049: Create event_locks table (5min TTL, permanent owner locks) - 050: Expand notification CHECK (calendar_invite types) - 051: Add updated_by to calendar_events + updated_at index New models: CalendarMember, EventLock Updated models: Calendar (is_shared, members), CalendarEvent (updated_by), Notification (3 new types) New schemas: shared_calendar.py (invite, respond, member, lock, sync) Updated schemas: calendar.py (is_shared, sharing response fields) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
36 lines
1.5 KiB
Python
36 lines
1.5 KiB
Python
from sqlalchemy import CheckConstraint, String, Text, Integer, Boolean, ForeignKey, func
|
|
from sqlalchemy.dialects.postgresql import JSONB
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
from app.database import Base
|
|
|
|
_NOTIFICATION_TYPES = (
|
|
"connection_request", "connection_accepted", "connection_rejected",
|
|
"calendar_invite", "calendar_invite_accepted", "calendar_invite_rejected",
|
|
"info", "warning", "reminder", "system",
|
|
)
|
|
|
|
|
|
class Notification(Base):
|
|
__tablename__ = "notifications"
|
|
__table_args__ = (
|
|
CheckConstraint(
|
|
f"type IN ({', '.join(repr(t) for t in _NOTIFICATION_TYPES)})",
|
|
name="ck_notifications_type",
|
|
),
|
|
)
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, index=True)
|
|
user_id: Mapped[int] = mapped_column(
|
|
Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False
|
|
)
|
|
type: Mapped[str] = mapped_column(String(50), nullable=False)
|
|
title: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
|
|
message: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
|
data: Mapped[Optional[dict]] = mapped_column(JSONB, nullable=True)
|
|
source_type: Mapped[Optional[str]] = mapped_column(String(50), nullable=True)
|
|
source_id: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
|
|
is_read: Mapped[bool] = mapped_column(Boolean, default=False, server_default="false")
|
|
created_at: Mapped[datetime] = mapped_column(default=func.now(), server_default=func.now())
|