28 lines
1.3 KiB
Python
28 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from sqlalchemy import DateTime, ForeignKey, Integer, String, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from ..database import Base
|
|
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from .team import Team
|
|
|
|
class NotificationLog(Base):
|
|
__tablename__ = "notification_logs"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
team_id: Mapped[int | None] = mapped_column(ForeignKey("teams.id", ondelete="SET NULL"), nullable=True)
|
|
event_type: Mapped[str] = mapped_column(String(60), nullable=False)
|
|
channel: Mapped[str] = mapped_column(String(20), default="email", nullable=False)
|
|
recipient: Mapped[str | None] = mapped_column(String(254), nullable=True)
|
|
subject: Mapped[str] = mapped_column(String(250), nullable=False)
|
|
body: Mapped[str] = mapped_column(Text, nullable=False)
|
|
status: Mapped[str] = mapped_column(String(20), nullable=False) # sent | skipped | failed
|
|
error: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
|
|
sent_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
|
|
|
team: Mapped[Team | None] = relationship()
|