43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
import uuid
|
|
from enum import Enum
|
|
from sqlalchemy import String, Boolean, ForeignKey, Enum as SQLEnum, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
from db.base import Base
|
|
|
|
class NotificationType(str, Enum):
|
|
PUBLIC = "public"
|
|
JOIN_REQUEST = "join_request"
|
|
|
|
class Notification(Base):
|
|
__tablename__ = "notifications" # type: ignore
|
|
|
|
title: Mapped[str] = mapped_column(String(200), nullable=False)
|
|
description: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
|
|
type: Mapped[NotificationType] = mapped_column(
|
|
SQLEnum(NotificationType, name="notification_type"),
|
|
nullable=False
|
|
)
|
|
|
|
is_accepted: Mapped[bool | None] = mapped_column(
|
|
Boolean,
|
|
nullable=True,
|
|
default=None
|
|
)
|
|
|
|
receiver_id: Mapped[uuid.UUID] = mapped_column(
|
|
ForeignKey("users.id", ondelete="CASCADE"),
|
|
index=True,
|
|
nullable=False
|
|
)
|
|
|
|
sender_id: Mapped[uuid.UUID | None] = mapped_column(
|
|
ForeignKey("users.id", ondelete="SET NULL"),
|
|
nullable=True
|
|
)
|
|
|
|
group_id: Mapped[uuid.UUID | None] = mapped_column(
|
|
ForeignKey("groups.id", ondelete="CASCADE"),
|
|
nullable=True
|
|
)
|