feat: complete subscription billing system phases 6-10
Phase 6 - Database-driven tiers: - Update subscription_service to query database first with legacy fallback - Add get_tier_info() db parameter and _get_tier_from_legacy() method Phase 7 - Platform health integration: - Add get_subscription_capacity() for theoretical vs actual capacity - Include subscription capacity in full health report Phase 8 - Background subscription tasks: - Add reset_period_counters() for billing period resets - Add check_trial_expirations() for trial management - Add sync_stripe_status() for Stripe synchronization - Add cleanup_stale_subscriptions() for maintenance - Add capture_capacity_snapshot() for daily metrics Phase 10 - Capacity planning & forecasting: - Add CapacitySnapshot model for historical tracking - Create capacity_forecast_service with growth trends - Add /subscription-capacity, /trends, /recommendations endpoints - Add /snapshot endpoint for manual captures Also includes billing API enhancements from phase 4: - Add upcoming-invoice, change-tier, addon purchase/cancel endpoints - Add UsageSummary schema for billing page - Enhance billing.js with addon management functions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
"""Add capacity_snapshots table
|
||||
|
||||
Revision ID: l0a1b2c3d4e5
|
||||
Revises: k9f0a1b2c3d4
|
||||
Create Date: 2025-12-26
|
||||
|
||||
Adds table for tracking daily platform capacity metrics for growth forecasting.
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "l0a1b2c3d4e5"
|
||||
down_revision = "k9f0a1b2c3d4"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"capacity_snapshots",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("snapshot_date", sa.DateTime(timezone=True), nullable=False),
|
||||
# Vendor metrics
|
||||
sa.Column("total_vendors", sa.Integer(), nullable=False, server_default="0"),
|
||||
sa.Column("active_vendors", sa.Integer(), nullable=False, server_default="0"),
|
||||
sa.Column("trial_vendors", sa.Integer(), nullable=False, server_default="0"),
|
||||
# Subscription metrics
|
||||
sa.Column("total_subscriptions", sa.Integer(), nullable=False, server_default="0"),
|
||||
sa.Column("active_subscriptions", sa.Integer(), nullable=False, server_default="0"),
|
||||
# Resource metrics
|
||||
sa.Column("total_products", sa.Integer(), nullable=False, server_default="0"),
|
||||
sa.Column("total_orders_month", sa.Integer(), nullable=False, server_default="0"),
|
||||
sa.Column("total_team_members", sa.Integer(), nullable=False, server_default="0"),
|
||||
# Storage metrics
|
||||
sa.Column("storage_used_gb", sa.Numeric(10, 2), nullable=False, server_default="0"),
|
||||
sa.Column("db_size_mb", sa.Numeric(10, 2), nullable=False, server_default="0"),
|
||||
# Capacity metrics
|
||||
sa.Column("theoretical_products_limit", sa.Integer(), nullable=True),
|
||||
sa.Column("theoretical_orders_limit", sa.Integer(), nullable=True),
|
||||
sa.Column("theoretical_team_limit", sa.Integer(), nullable=True),
|
||||
# Tier distribution
|
||||
sa.Column("tier_distribution", sa.JSON(), nullable=True),
|
||||
# Performance metrics
|
||||
sa.Column("avg_response_ms", sa.Integer(), nullable=True),
|
||||
sa.Column("peak_cpu_percent", sa.Numeric(5, 2), nullable=True),
|
||||
sa.Column("peak_memory_percent", sa.Numeric(5, 2), nullable=True),
|
||||
# Timestamps
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
||||
# Primary key
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
|
||||
# Create indexes
|
||||
op.create_index("ix_capacity_snapshots_id", "capacity_snapshots", ["id"], unique=False)
|
||||
op.create_index("ix_capacity_snapshots_date", "capacity_snapshots", ["snapshot_date"], unique=True)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index("ix_capacity_snapshots_date", table_name="capacity_snapshots")
|
||||
op.drop_index("ix_capacity_snapshots_id", table_name="capacity_snapshots")
|
||||
op.drop_table("capacity_snapshots")
|
||||
Reference in New Issue
Block a user