Files
resolutionflow/backend/alembic/versions/030_enhance_invite_codes.py
Michael Chihlas 50cb0fc7f0 feat: admin invite codes with plan assignment + user detail page
- Migration 030: add email, assigned_plan, trial_duration_days, email_sent_at
  to invite_codes with CHECK constraints
- Resend email integration (graceful degradation when API key not set)
- Invite codes now support plan assignment (free/pro/team) and trial duration (1-90 days)
- Registration applies invite code plan/trial to new subscription
- Auto-downgrade expired trials on authenticated access
- Enriched GET /admin/users/{id} with account, subscription, sessions, audit logs
- New endpoints: PUT /admin/users/{id}/subscription/plan and extend-trial
- Frontend: enhanced invite codes page with email, plan, trial fields
- Frontend: new user detail page at /admin/users/:userId
- Fixed API path drift: /invite-codes -> /invites
- 11 new backend tests, 416 total passing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 21:42:58 -05:00

62 lines
2.2 KiB
Python

"""enhance invite codes with plan assignment and email
Revision ID: 030
Revises: 029
Create Date: 2026-02-12
Adds email, assigned_plan, trial_duration_days, and email_sent_at columns
to invite_codes table for plan-aware invite code creation.
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '030'
down_revision: Union[str, None] = '029'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.add_column('invite_codes', sa.Column('email', sa.String(255), nullable=True))
op.add_column('invite_codes', sa.Column('assigned_plan', sa.String(50), nullable=False, server_default='free'))
op.add_column('invite_codes', sa.Column('trial_duration_days', sa.Integer(), nullable=True))
op.add_column('invite_codes', sa.Column('email_sent_at', sa.DateTime(timezone=True), nullable=True))
op.create_index('ix_invite_codes_email', 'invite_codes', ['email'])
# Plan must be free/pro/team
op.create_check_constraint(
'ck_invite_codes_assigned_plan',
'invite_codes',
"assigned_plan IN ('free', 'pro', 'team')"
)
# Trial duration 1-90 days or NULL
op.create_check_constraint(
'ck_invite_codes_trial_duration',
'invite_codes',
"trial_duration_days IS NULL OR (trial_duration_days >= 1 AND trial_duration_days <= 90)"
)
# Free plan cannot have trial duration
op.create_check_constraint(
'ck_invite_codes_free_no_trial',
'invite_codes',
"assigned_plan != 'free' OR trial_duration_days IS NULL"
)
def downgrade() -> None:
op.drop_constraint('ck_invite_codes_free_no_trial', 'invite_codes', type_='check')
op.drop_constraint('ck_invite_codes_trial_duration', 'invite_codes', type_='check')
op.drop_constraint('ck_invite_codes_assigned_plan', 'invite_codes', type_='check')
op.drop_index('ix_invite_codes_email', table_name='invite_codes')
op.drop_column('invite_codes', 'email_sent_at')
op.drop_column('invite_codes', 'trial_duration_days')
op.drop_column('invite_codes', 'assigned_plan')
op.drop_column('invite_codes', 'email')