notification_lock_screen_widget.py 1.5 KB

12345678910111213141516171819202122232425262728
  1. """Durable ownership of one persistent Notify! widget per printer/provider."""
  2. from datetime import datetime
  3. from sqlalchemy import DateTime, ForeignKey, Integer, String, Text, UniqueConstraint
  4. from sqlalchemy.orm import Mapped, mapped_column
  5. from backend.app.core.database import Base
  6. class NotificationLockScreenWidget(Base):
  7. __tablename__ = "notification_lock_screen_widgets"
  8. __table_args__ = (UniqueConstraint("provider_id", "printer_id"),)
  9. id: Mapped[int] = mapped_column(Integer, primary_key=True)
  10. provider_id: Mapped[int] = mapped_column(
  11. Integer, ForeignKey("notification_providers.id", ondelete="CASCADE"), nullable=False, index=True
  12. )
  13. # A removed printer must leave ownership intact until the remote DELETE succeeds.
  14. printer_id: Mapped[int] = mapped_column(Integer, nullable=False, index=True)
  15. credential_key: Mapped[str] = mapped_column(String(64), nullable=False)
  16. widget_id: Mapped[str | None] = mapped_column(String(16), nullable=True)
  17. state: Mapped[str] = mapped_column(String(20), nullable=False, default="pending")
  18. content: Mapped[str] = mapped_column(Text, nullable=False, default="{}")
  19. failures: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
  20. next_attempt_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
  21. last_sent_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
  22. created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=datetime.utcnow)