"""Add Product.is_tax_applicable

Revision ID: a3e70f4c4e1e
Revises: b61e1c9fa805
Create Date: 2024-12-17 17:32:38.258158

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

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


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        "products", sa.Column("is_tax_applicable", sa.Boolean(), nullable=True)
    )

    op.execute(
        """
        UPDATE products
        SET is_tax_applicable = TRUE
        """
    )
    op.execute(
        """
        UPDATE products
        SET is_tax_applicable = FALSE
        WHERE user_metadata->>'donation_product' = 'true'
        """
    )

    op.alter_column("products", "is_tax_applicable", nullable=False)

    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column("products", "is_tax_applicable")
    # ### end Alembic commands ###
