Files
replypier/backend/alembic/versions/add_investigation_metered.py
T
WangShen007 2aee6286d6 build: 打通 FastAPI 与 Vue 最小工程、依赖与数据库连接
后端入口、配置、Redis 与 Alembic 迁移就位;前端 Vite 工程可安装可构建。
2026-09-22 20:15:00 +08:00

42 lines
1.2 KiB
Python

"""Add metered flag to investigation_runs
Revision ID: add_tkt_metered_001
Revises: add_tkt_row_scope_001
Create Date: 2026-07-21
Marks whether an investigation run's LLM usage counts against the org's message
budget (hosted model only). Existing rows default to false — nothing is
retroactively metered on upgrade.
"""
from alembic import op
import sqlalchemy as sa
revision = "add_tkt_metered_001"
down_revision = "add_tkt_row_scope_001"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.add_column(
"investigation_runs",
sa.Column(
"metered",
sa.Boolean(),
nullable=False,
server_default=sa.text("false"),
),
)
# The enterprise message-limit check sums llm_calls of metered runs per
# billing window — an index on (org, metered, created_at) keeps that cheap.
op.create_index(
"ix_investigation_runs_metered_period",
"investigation_runs",
["organization_id", "metered", "created_at"],
)
def downgrade() -> None:
op.drop_index("ix_investigation_runs_metered_period", table_name="investigation_runs")
op.drop_column("investigation_runs", "metered")