"""Cleanup and optimize indices

Revision ID: 16b19486b490
Revises: 83ad16407f2f
Create Date: 2025-01-31 14:33:31.317433

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "16b19486b490"
down_revision = "83ad16407f2f"
branch_labels: tuple[str] | None = None
depends_on: tuple[str] | None = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index("ix_benefit_grants_subscription_id", table_name="benefit_grants")
    op.create_index(
        op.f("ix_checkouts_expires_at"), "checkouts", ["expires_at"], unique=False
    )
    op.drop_index("ix_custom_fields_slug", table_name="custom_fields")
    op.drop_index("ix_downloadables_customer_id", table_name="downloadables")
    op.drop_index("idx_issues_pledged_amount_sum", table_name="issues")
    op.drop_index("ix_issues_organization_id", table_name="issues")
    op.drop_index("ix_oauth2_clients_client_id", table_name="oauth2_clients")
    op.drop_index("ix_pledges_issue_id", table_name="pledges")
    op.drop_index("idx_deleted_at_is_private", table_name="repositories")
    op.create_index(
        op.f("ix_repositories_is_private"), "repositories", ["is_private"], unique=False
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_repositories_is_private"), table_name="repositories")
    op.create_index(
        "idx_deleted_at_is_private",
        "repositories",
        ["deleted_at", "is_private"],
        unique=False,
    )
    op.create_index("ix_pledges_issue_id", "pledges", ["issue_id"], unique=False)
    op.create_index(
        "ix_oauth2_clients_client_id", "oauth2_clients", ["client_id"], unique=False
    )
    op.create_index(
        "ix_issues_organization_id", "issues", ["organization_id"], unique=False
    )
    op.create_index(
        "idx_issues_pledged_amount_sum", "issues", ["pledged_amount_sum"], unique=False
    )
    op.create_index(
        "ix_downloadables_customer_id", "downloadables", ["customer_id"], unique=False
    )
    op.create_index("ix_custom_fields_slug", "custom_fields", ["slug"], unique=False)
    op.drop_index(op.f("ix_checkouts_expires_at"), table_name="checkouts")
    op.create_index(
        "ix_benefit_grants_subscription_id",
        "benefit_grants",
        ["subscription_id"],
        unique=False,
    )
    # ### end Alembic commands ###
