"""Add Product.tax_code

Revision ID: fba2f31e6d5a
Revises: 902dd5c6c2b7
Create Date: 2025-10-22 11:18:53.212185

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "fba2f31e6d5a"
down_revision = "902dd5c6c2b7"
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("tax_code", sa.String(), nullable=True),
    )

    op.execute(
        """
        UPDATE products
        SET tax_code = 'general_electronically_supplied_services'
        WHERE tax_code IS NULL
        """
    )

    op.alter_column(
        "products",
        "tax_code",
        existing_type=sa.String(),
        nullable=False,
    )

    # ### end Alembic commands ###


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