41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
"""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 = 'control0003_trial_reminder_sent'
|
|
down_revision = 'control0002_billing'
|
|
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"
|
|
))
|