"""add collection commerce landing metadata

Revision ID: 0059_add_collection_commerce_landing_metadata
Revises: 0058_merge_collection_start_shopping_and_normalization_heads
Create Date: 2026-07-21 16:20:00.000000
"""

from alembic import op
import sqlalchemy as sa
from sqlalchemy import inspect
from sqlalchemy.dialects import postgresql


# revision identifiers, used by Alembic.
revision = "0059_add_collection_commerce_landing_metadata"
down_revision = "0058_merge_collection_start_shopping_and_normalization_heads"
branch_labels = None
depends_on = None


def upgrade() -> None:
    bind = op.get_bind()
    inspector = inspect(bind)
    columns = {column["name"] for column in inspector.get_columns("collection_commerce_profile")}
    if "landing_metadata_json" not in columns:
        op.add_column(
            "collection_commerce_profile",
            sa.Column("landing_metadata_json", postgresql.JSONB(astext_type=sa.Text()), nullable=True),
        )


def downgrade() -> None:
    bind = op.get_bind()
    inspector = inspect(bind)
    columns = {column["name"] for column in inspector.get_columns("collection_commerce_profile")}
    if "landing_metadata_json" in columns:
        op.drop_column("collection_commerce_profile", "landing_metadata_json")
