"""Add indices to BillingEntry to optimize queries

Revision ID: 15fd38497594
Revises: d784000f1f80
Create Date: 2025-08-27 17:17:13.135665

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "15fd38497594"
down_revision = "d784000f1f80"
branch_labels: tuple[str] | None = None
depends_on: tuple[str] | None = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_index(
        "ix_billing_entries_s_d_oi_pp",
        "billing_entry",
        ["subscription_id", "deleted_at", "order_item_id", "product_price_id"],
        unique=False,
        if_not_exists=True,
    )
    op.create_index(
        "ix_billing_entries_s_oi_pp",
        "billing_entry",
        ["subscription_id", "order_item_id", "product_price_id"],
        unique=False,
        if_not_exists=True,
    )
    op.create_index(
        op.f("ix_billing_entry_order_item_id"),
        "billing_entry",
        ["order_item_id"],
        unique=False,
        if_not_exists=True,
    )
    op.create_index(
        op.f("ix_billing_entry_product_price_id"),
        "billing_entry",
        ["product_price_id"],
        unique=False,
        if_not_exists=True,
    )
    op.create_index(
        op.f("ix_billing_entry_subscription_id"),
        "billing_entry",
        ["subscription_id"],
        unique=False,
        if_not_exists=True,
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_billing_entry_subscription_id"), table_name="billing_entry")
    op.drop_index(op.f("ix_billing_entry_product_price_id"), table_name="billing_entry")
    op.drop_index(op.f("ix_billing_entry_order_item_id"), table_name="billing_entry")
    op.drop_index("ix_billing_entries_s_oi_pp", table_name="billing_entry")
    op.drop_index("ix_billing_entries_s_d_oi_pp", table_name="billing_entry")
    # ### end Alembic commands ###
