"""Discount, ignore soft-deletes

Revision ID: c2d5a5c0b974
Revises: 197161f42f14
Create Date: 2025-07-02 11:03:22.746985

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "c2d5a5c0b974"
down_revision = "197161f42f14"
branch_labels: tuple[str] | None = None
depends_on: tuple[str] | None = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(
        op.f("discounts_organization_id_code_key"), "discounts", type_="unique"
    )
    op.create_index(
        "ix_discounts_code_uniqueness",
        "discounts",
        ["organization_id", sa.literal_column("lower(code)")],
        unique=True,
        postgresql_where=sa.text("deleted_at IS NULL"),
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(
        "ix_discounts_code_uniqueness",
        table_name="discounts",
        postgresql_where=sa.text("deleted_at IS NULL"),
    )
    op.create_unique_constraint(
        op.f("discounts_organization_id_code_key"),
        "discounts",
        ["organization_id", "code"],
        postgresql_nulls_not_distinct=False,
    )
    # ### end Alembic commands ###
