"""usage records

Revision ID: 42f06c63e00f
Revises: c7a5347c0896
Create Date: 2026-07-01 17:10:16.813944
"""

from __future__ import annotations

from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision: str = "42f06c63e00f"
down_revision: str | None = "c7a5347c0896"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "usage_records",
        sa.Column("workspace_id", sa.Uuid(), nullable=False),
        sa.Column("metric", sa.String(length=50), nullable=False),
        sa.Column("quantity", sa.BigInteger(), nullable=False),
        sa.Column("period", sa.String(length=7), nullable=False),
        sa.Column("id", sa.Uuid(), nullable=False),
        sa.Column(
            "created_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("(CURRENT_TIMESTAMP)"),
            nullable=False,
        ),
        sa.Column(
            "updated_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("(CURRENT_TIMESTAMP)"),
            nullable=False,
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_usage_records_workspace_id"), "usage_records", ["workspace_id"], unique=False
    )
    op.create_index(
        "ix_usage_ws_metric_period",
        "usage_records",
        ["workspace_id", "metric", "period"],
        unique=False,
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index("ix_usage_ws_metric_period", table_name="usage_records")
    op.drop_index(op.f("ix_usage_records_workspace_id"), table_name="usage_records")
    op.drop_table("usage_records")
    # ### end Alembic commands ###
