2a107a42f3
- New DB models: credit_packages, subscription_plans, user_credits, credit_consumptions, credit_purchases - CreditService: balance, deduct, add_credits, grant_free_trial, history - User API: /api/v1/credits/* (balance/history/packages/purchase/subscribe) - Admin API: /api/v1/admin/credit-* (CRUD packages/plans, user credits, consumptions) - PaymentService.create_credit_order + handle_callback for credit purchases - Credit deduction on: discovery, translate, marketing, ai_chat, followup - Free trial 30 credits on registration - Documentation: docs/CREDIT_SYSTEM.md
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
"""add performance indexes
|
|
|
|
Revision ID: add_perf_indexes
|
|
Revises: add_payment_transactions_table
|
|
Create Date: 2026-06-11
|
|
|
|
Add indexes for common query patterns to improve performance.
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = 'add_perf_indexes'
|
|
down_revision = 'add_payment_transactions'
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# Customer indexes
|
|
op.create_index('ix_customer_user_status', 'customers', ['user_id', 'status'])
|
|
op.create_index('ix_customer_user_last_contact', 'customers', ['user_id', 'last_contact_at'])
|
|
|
|
# Payment transaction indexes
|
|
op.create_index('ix_payment_user_created', 'payment_transactions', ['user_id', 'created_at'])
|
|
|
|
# Followup log indexes
|
|
op.create_index('ix_followup_user_customer', 'followup_logs', ['user_id', 'customer_id'])
|
|
|
|
# Notification indexes
|
|
op.create_index('ix_notification_user_read', 'notifications', ['user_id', 'is_read'])
|
|
|
|
|
|
def downgrade() -> None:
|
|
# Remove indexes
|
|
op.drop_index('ix_notification_user_read', 'notifications')
|
|
op.drop_index('ix_followup_user_customer', 'followup_logs')
|
|
op.drop_index('ix_payment_user_created', 'payment_transactions')
|
|
op.drop_index('ix_customer_user_last_contact', 'customers')
|
|
op.drop_index('ix_customer_user_status', 'customers') |