Files
gh-christianlouis-docuelevate/migrations/versions/016_add_userprofile_billing.py
T
copilot-swe-agent[bot] ea7fffa3a1 feat(subscriptions): database-backed plan designer with admin CRUD and overage buffer
- Add SubscriptionPlan model and subscription_plans table (migration 015)
- Add billing cycle/period/allow_overage fields to UserProfile (migration 016)
- Add subscription_overage_percent config field (replaces overage_factor)
- Rewrite check_upload_allowed: use overage_percent, yearly carry-over, no daily cap
- Add seed_default_plans(), _plan_to_dict(), get_year_file_count(), _months_elapsed()
- Update get_tier/get_all_tiers to be DB-first with TIER_DEFAULTS fallback
- Add TIER_DEFAULTS alias (TIERS kept for backward compat)
- New /api/plans/ CRUD endpoints (admin-only except list/get)
- New /admin/plans Plan Designer page with Alpine.js UI
- Add Plan Designer link to admin navigation in base.html
- Remove 'Files per day' row from pricing comparison table
- Add billing cycle + period start to admin users edit modal
- Seed default plans on startup in lifespan handler
- Rewrite docs/SubscriptionTiers.md with full plan/overage/API docs
- Fix all tests in test_subscription.py (remove daily cap tests, add overage/carry-over tests)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-06 18:48:27 +00:00

46 lines
1.3 KiB
Python

"""Add billing cycle and overage columns to user_profiles
Revision ID: 016_add_userprofile_billing
Revises: 015_add_subscription_plans
Create Date: 2026-03-07
"""
from typing import Union
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision: str = "016_add_userprofile_billing"
down_revision: Union[str, None] = "015_add_subscription_plans"
depends_on: Union[str, None] = None
def upgrade() -> None:
"""Add subscription_billing_cycle, subscription_period_start, allow_overage to user_profiles."""
op.add_column(
"user_profiles",
sa.Column(
"subscription_billing_cycle",
sa.String(10),
nullable=False,
server_default="monthly",
),
)
op.add_column(
"user_profiles",
sa.Column("subscription_period_start", sa.DateTime(timezone=True), nullable=True),
)
op.add_column(
"user_profiles",
sa.Column("allow_overage", sa.Boolean(), nullable=False, server_default="0"),
)
def downgrade() -> None:
"""Remove billing columns from user_profiles."""
op.drop_column("user_profiles", "allow_overage")
op.drop_column("user_profiles", "subscription_period_start")
op.drop_column("user_profiles", "subscription_billing_cycle")