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

38 lines
1.2 KiB
Python

import uuid
from sqlalchemy import Column, Date, DateTime, ForeignKey, String, UniqueConstraint, func
from sqlalchemy.dialects.postgresql import UUID
from app.config.database import Base
class SubscriptionNotice(Base):
"""A record that a workspace has already been told something.
Exists so a worker running twice in a day does not send the same warning
twice. Keyed on the end date the notice was *about*, so a renewal starts a
fresh cycle and next time's warning fires normally.
"""
__tablename__ = "subscription_notices"
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
tenant_id = Column(
UUID(as_uuid=True), ForeignKey("tenants.id", ondelete="CASCADE"),
nullable=False, index=True,
)
kind = Column(String(30), nullable=False)
for_end_date = Column(Date, nullable=True)
sent_to = Column(String(255), nullable=True)
sent_at = Column(DateTime(timezone=True), server_default=func.now(), nullable=False)
__table_args__ = (
UniqueConstraint(
"tenant_id", "kind", "for_end_date", name="uq_subscription_notice_once"
),
)
def __repr__(self) -> str:
return f"<SubscriptionNotice {self.kind} {self.tenant_id}>"