backend: add push token API and FCM delivery pipeline

This commit is contained in:
Codex
2026-03-09 23:12:19 +03:00
parent e82178fcc3
commit 74b086b9c8
11 changed files with 296 additions and 13 deletions

View File

@@ -1,6 +1,6 @@
from datetime import datetime
from sqlalchemy import DateTime, String, func
from sqlalchemy import DateTime, ForeignKey, String, UniqueConstraint, func
from sqlalchemy.orm import Mapped, mapped_column
from app.database.base import Base
@@ -14,3 +14,22 @@ class NotificationLog(Base):
event_type: Mapped[str] = mapped_column(String(64), index=True)
payload: Mapped[str] = mapped_column(String(1024))
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), nullable=False)
class PushDeviceToken(Base):
__tablename__ = "push_device_tokens"
__table_args__ = (UniqueConstraint("user_id", "platform", "token", name="uq_push_device_tokens_user_platform_token"),)
id: Mapped[int] = mapped_column(primary_key=True, index=True)
user_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True)
platform: Mapped[str] = mapped_column(String(16), nullable=False, index=True)
token: Mapped[str] = mapped_column(String(512), nullable=False)
device_id: Mapped[str | None] = mapped_column(String(128), nullable=True)
app_version: Mapped[str | None] = mapped_column(String(64), nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), nullable=False)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
server_default=func.now(),
onupdate=func.now(),
nullable=False,
)