user_email_pref.py 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. """User email notification preference model."""
  2. from datetime import datetime
  3. from sqlalchemy import Boolean, DateTime, ForeignKey, Integer, func
  4. from sqlalchemy.orm import Mapped, mapped_column, relationship
  5. from backend.app.core.database import Base
  6. class UserEmailPreference(Base):
  7. """Stores per-user email notification preferences for their own print jobs."""
  8. __tablename__ = "user_email_preferences"
  9. id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
  10. user_id: Mapped[int] = mapped_column(
  11. Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False, unique=True, index=True
  12. )
  13. # Print lifecycle notifications (only for jobs submitted by this user)
  14. notify_print_start: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
  15. notify_print_complete: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
  16. notify_print_failed: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
  17. notify_print_stopped: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
  18. created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
  19. updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now())
  20. # Relationship
  21. user: Mapped["User"] = relationship(back_populates="email_preferences")