Jun 29 - Add trial reminder sent function

This commit is contained in:
2026-06-29 10:04:45 -04:00
parent 42790c499c
commit 7022e46942
5 changed files with 487 additions and 4 deletions
@@ -0,0 +1,40 @@
"""control0002 — add trial_reminder_sent_at to tenants
Adds a nullable DATETIME column that the trial-reminders cron endpoint writes
to after dispatching a warning email. Prevents duplicate sends within 22 hours.
"""
import sqlalchemy as sa
from alembic import op
revision = 'control0002_trial_reminder_sent'
down_revision = 'control0001_init'
branch_labels = None
depends_on = None
def _col_exists(bind, table, column):
result = bind.execute(sa.text(
"SELECT COUNT(*) FROM information_schema.columns "
"WHERE table_schema = DATABASE() "
"AND table_name = :t AND column_name = :c"
), {'t': table, 'c': column})
return result.scalar() > 0
def upgrade():
bind = op.get_bind()
if not _col_exists(bind, 'tenants', 'trial_reminder_sent_at'):
op.execute(sa.text(
"ALTER TABLE tenants "
"ADD COLUMN trial_reminder_sent_at DATETIME NULL "
"AFTER trial_ends_at"
))
def downgrade():
bind = op.get_bind()
if _col_exists(bind, 'tenants', 'trial_reminder_sent_at'):
op.execute(sa.text(
"ALTER TABLE tenants DROP COLUMN trial_reminder_sent_at"
))
+4 -3
View File
@@ -108,9 +108,10 @@ class Tenant(ControlBase):
Enum('trial', 'active', 'past_due', 'cancelled', name='subscription_status'),
nullable=True,
)
trial_ends_at = Column(DateTime, nullable=True)
current_period_end = Column(DateTime, nullable=True)
billing_email = Column(String(255), nullable=True)
trial_ends_at = Column(DateTime, nullable=True)
trial_reminder_sent_at = Column(DateTime, nullable=True) # set after trial warning email
current_period_end = Column(DateTime, nullable=True)
billing_email = Column(String(255), nullable=True)
plan = relationship('Plan', back_populates='tenants')
domains = relationship('TenantDomain', back_populates='tenant',