27 lines
1.2 KiB
Python
27 lines
1.2 KiB
Python
from datetime import datetime, timezone
|
|
from typing import Optional
|
|
from sqlalchemy import Index, Integer, String, DateTime, Text, ForeignKey, text
|
|
from sqlalchemy.orm import mapped_column, Mapped
|
|
from app.database import Base
|
|
|
|
|
|
class NotificationLog(Base):
|
|
__tablename__ = "notification_logs"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
|
|
webhook_config_id: Mapped[int] = mapped_column(
|
|
Integer, ForeignKey("webhook_configs.id", ondelete="CASCADE"), index=True
|
|
)
|
|
webhook_name: Mapped[str] = mapped_column(String(255), default="")
|
|
event_type: Mapped[str] = mapped_column(String(64), nullable=False)
|
|
payload_json: Mapped[str] = mapped_column(Text, default="{}")
|
|
# success | failed
|
|
status: Mapped[str] = mapped_column(String(16), nullable=False)
|
|
response_text: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=lambda: datetime.now(timezone.utc), index=True)
|
|
|
|
__table_args__ = (
|
|
Index("ix_notif_event_created", "event_type", text("created_at DESC")),
|
|
Index("ix_notif_status_created", "status", text("created_at DESC")),
|
|
)
|