# alembic/versions/x2c3d4e5f6g7_make_marketplace_product_id_nullable.py
"""Make marketplace_product_id nullable for direct product creation.

Revision ID: x2c3d4e5f6g7
Revises: w1b2c3d4e5f6
Create Date: 2026-01-06 23:15:00.000000

"""

from collections.abc import Sequence

import sqlalchemy as sa

from alembic import op

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


def upgrade() -> None:
    """Make marketplace_product_id nullable to allow direct product creation."""
    # SQLite doesn't support ALTER COLUMN, so we need to recreate the table
    # For SQLite, we use batch mode which handles this automatically
    with op.batch_alter_table("products") as batch_op:
        batch_op.alter_column(
            "marketplace_product_id",
            existing_type=sa.Integer(),
            nullable=True,
        )


def downgrade() -> None:
    """Revert marketplace_product_id to NOT NULL."""
    # Note: This will fail if there are any NULL values in the column
    with op.batch_alter_table("products") as batch_op:
        batch_op.alter_column(
            "marketplace_product_id",
            existing_type=sa.Integer(),
            nullable=False,
        )
