Spaces:
Sleeping
Sleeping
| from __future__ import annotations | |
| from datetime import datetime | |
| from uuid import uuid4 | |
| from sqlalchemy import String, ForeignKey, Boolean, DateTime, Index, UniqueConstraint | |
| from sqlalchemy.orm import Mapped, mapped_column | |
| from app.security.models import Base, utcnow | |
| class NotificationPreference(Base): | |
| __tablename__ = "notification_preferences" | |
| __table_args__ = ( | |
| UniqueConstraint("workspace_id", "user_id", "event_type", name="uq_notification_preference"), | |
| Index("ix_notification_preferences_workspace_user", "workspace_id", "user_id"), | |
| ) | |
| id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid4())) | |
| workspace_id: Mapped[str] = mapped_column(String(36), ForeignKey("workspaces.id", ondelete="CASCADE"), nullable=False) | |
| user_id: Mapped[str] = mapped_column(String(36), ForeignKey("users.id", ondelete="CASCADE"), nullable=False) | |
| event_type: Mapped[str] = mapped_column(String(50), nullable=False) | |
| enabled: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True) | |
| created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False, default=utcnow) | |