The marketing surface (PricingPage, Stripe products) was wired for "Starter / Pro / Enterprise" while the backend was on "free / pro / team", leaving plan_billing unseeded and BillingPlan accepting a literal that violated the FK to plan_limits. This change: - Migration 4ce3e594cb87: defensive UPDATE of any subscriptions on plan='team' to 'enterprise' (dev has zero), renames the plan_limits row team -> enterprise, inserts a starter row with caps interpolated between free and pro (max_trees=10, sessions=75, ai=15/mo). - Renames the plan tier across schemas (invite_code, billing, admin, subscription comment), is_paid/has_pro_entitlement checks in the Subscription model, admin/admin_dashboard plan validators, and the frontend useSubscription isPaidPlan check. Resource visibility uses the same string 'team' in a separate domain (Tree/StepLibrary visibility) and is intentionally untouched. - New backend/scripts/sync_stripe_plan_ids.py: idempotent upsert of plan_billing rows from Stripe products by exact name match. Picks the active monthly recurring price for tiers that have one; leaves annual fields NULL by design. Works against test or live keys. - Test fixture updates: conftest seeds the new taxonomy, the public plans helper is a true upsert so tests can override max_users, and team -> enterprise across test_admin_plan_limits and test_invite_plan. Verified: 86/86 passing across the subscription/billing/plan/invite/ admin sweep; sync script run against test mode populates plan_billing correctly for all three tiers. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
from datetime import datetime
|
|
from typing import Literal, Optional
|
|
from uuid import UUID
|
|
from pydantic import BaseModel, EmailStr, Field, model_validator
|
|
|
|
|
|
class InviteCodeCreate(BaseModel):
|
|
"""Schema for creating a new invite code."""
|
|
expires_at: Optional[datetime] = Field(None, description="Optional expiration time")
|
|
note: Optional[str] = Field(None, max_length=255, description="Note about who this code is for")
|
|
email: Optional[EmailStr] = Field(None, description="Recipient email for invite delivery")
|
|
assigned_plan: Literal["free", "pro", "starter", "enterprise"] = Field("free", description="Plan to assign on registration")
|
|
trial_duration_days: Optional[int] = Field(None, ge=1, le=90, description="Trial duration in days (1-90)")
|
|
|
|
@model_validator(mode="after")
|
|
def free_plan_no_trial(self):
|
|
if self.assigned_plan == "free" and self.trial_duration_days is not None:
|
|
raise ValueError("Free plan cannot have a trial duration")
|
|
return self
|
|
|
|
|
|
class InviteCodeResponse(BaseModel):
|
|
"""Schema for invite code response."""
|
|
id: UUID
|
|
code: str
|
|
created_by_id: UUID
|
|
used_by_id: Optional[UUID] = None
|
|
expires_at: Optional[datetime] = None
|
|
note: Optional[str] = None
|
|
created_at: datetime
|
|
used_at: Optional[datetime] = None
|
|
is_used: bool
|
|
is_expired: bool
|
|
is_valid: bool
|
|
email: Optional[str] = None
|
|
assigned_plan: str = "free"
|
|
trial_duration_days: Optional[int] = None
|
|
email_sent_at: Optional[datetime] = None
|
|
has_trial: bool = False
|
|
email_sent: bool = False
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class InviteCodeValidation(BaseModel):
|
|
"""Schema for invite code validation response."""
|
|
valid: bool
|
|
message: str
|