Files
saas_backend/app/models/system/notification_preference_model.py
T
2026-08-31 20:39:41 -04:00

33 lines
1.2 KiB
Python

"""What somebody has chosen not to be told about.
A row exists only when a preference differs from the default. Absence means
enabled — see the migration for why that is the right way round.
"""
from __future__ import annotations
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, String, func
from sqlalchemy.dialects.postgresql import UUID
from app.config.database import Base
IN_APP = "in_app"
EMAIL = "email"
CHANNELS = (IN_APP, EMAIL)
class NotificationPreference(Base):
__tablename__ = "notification_preferences"
id = Column(UUID(as_uuid=True), primary_key=True,
server_default=func.gen_random_uuid())
tenant_id = Column(UUID(as_uuid=True), ForeignKey("tenants.id", ondelete="CASCADE"))
user_id = Column(UUID(as_uuid=True), ForeignKey("users.id", ondelete="CASCADE"),
nullable=False)
notification_type = Column(String(100), nullable=False)
channel = Column(String(50), nullable=False, default=IN_APP)
enabled = Column(Boolean, nullable=False, default=True)
created_at = Column(DateTime(timezone=True), nullable=False, server_default=func.now())
updated_at = Column(DateTime(timezone=True), nullable=False,
server_default=func.now(), onupdate=func.now())