47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
"""Add token tracking columns for folder integration.
|
|
|
|
Revision ID: d6e3f4a5b6c7
|
|
Revises: 006
|
|
Create Date: 2026-05-11 00:00:00.000000
|
|
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Sequence, Union
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = "d6e3f4a5b6c7"
|
|
down_revision: Union[str, None] = "006"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.add_column(
|
|
"agent_run_logs",
|
|
sa.Column("tokens_used", sa.Integer(), nullable=False, server_default="0"),
|
|
)
|
|
op.create_table(
|
|
"monthly_token_usage",
|
|
sa.Column("user_id", UUID(as_uuid=False), sa.ForeignKey("users.id", ondelete="CASCADE"), nullable=False),
|
|
sa.Column("year_month", sa.String(7), nullable=False),
|
|
sa.Column("feature", sa.String(64), nullable=False),
|
|
sa.Column("tokens_used", sa.Integer(), nullable=False, server_default="0"),
|
|
sa.PrimaryKeyConstraint("user_id", "year_month", "feature"),
|
|
)
|
|
op.create_index(
|
|
"ix_monthly_token_usage_user_month",
|
|
"monthly_token_usage",
|
|
["user_id", "year_month"],
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index("ix_monthly_token_usage_user_month", table_name="monthly_token_usage")
|
|
op.drop_table("monthly_token_usage")
|
|
op.drop_column("agent_run_logs", "tokens_used")
|