"""Add partial index for webhook_events.payload NULL values

Revision ID: 09970077f986
Revises: d96c81cf1e57
Create Date: 2025-09-10 18:02:17.461079

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "09970077f986"
down_revision = "d96c81cf1e57"
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_webhook_events_created_at_non_archived",
            "webhook_events",
            ["created_at"],
            unique=False,
            postgresql_where="payload IS NOT NULL",
            postgresql_concurrently=True,
        )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(
        "ix_webhook_events_created_at_non_archived",
        table_name="webhook_events",
        postgresql_where="payload IS NOT NULL",
    )
    # ### end Alembic commands ###
