# alembic/versions/y3d4e5f6g7h8_add_product_type_columns.py
"""Add is_digital and product_type columns to products table.

Makes Product fully independent from MarketplaceProduct for product type info.

Revision ID: y3d4e5f6g7h8
Revises: x2c3d4e5f6g7
Create Date: 2026-01-07 10:00:00.000000

"""

from collections.abc import Sequence

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "y3d4e5f6g7h8"
down_revision: str = "x2c3d4e5f6g7"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    """Add is_digital and product_type columns to products table."""
    with op.batch_alter_table("products") as batch_op:
        batch_op.add_column(
            sa.Column("is_digital", sa.Boolean(), nullable=False, server_default="0")
        )
        batch_op.add_column(
            sa.Column(
                "product_type",
                sa.String(20),
                nullable=False,
                server_default="physical",
            )
        )
        batch_op.create_index("idx_product_is_digital", ["is_digital"])


def downgrade() -> None:
    """Remove is_digital and product_type columns."""
    with op.batch_alter_table("products") as batch_op:
        batch_op.drop_index("idx_product_is_digital")
        batch_op.drop_column("product_type")
        batch_op.drop_column("is_digital")
