"""Add index on customer_id ingested at desc

Revision ID: f5223877acbb
Revises: 49b4ad646404
Create Date: 2025-11-27 16:01:40.695809

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "f5223877acbb"
down_revision = "49b4ad646404"
branch_labels: tuple[str] | None = None
depends_on: tuple[str] | None = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    with op.get_context().autocommit_block():
        op.create_index(
            "ix_events_organization_customer_id_ingested_at_desc",
            "events",
            ["organization_id", "customer_id", sa.literal_column("ingested_at DESC")],
            unique=False,
            postgresql_concurrently=True,
        )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(
        "ix_events_organization_customer_id_ingested_at_desc", table_name="events"
    )
    # ### end Alembic commands ###
