"""add featured label to product categories

Revision ID: 022_featured_label
Revises: 021_instance_real_data_snapshots
Create Date: 2026-06-12
"""

from alembic import op
import sqlalchemy as sa

revision = "022_featured_label"
down_revision = "021_instance_real_data_snapshots"
branch_labels = None
depends_on = None


def upgrade() -> None:
    bind = op.get_bind()
    columns = {column["name"] for column in sa.inspect(bind).get_columns("product_categories")}
    if "featured_label" not in columns:
        op.add_column(
            "product_categories",
            sa.Column(
                "featured_label",
                sa.String(length=24),
                nullable=False,
                server_default="推荐",
                comment="首页推荐标签显示文字",
            ),
        )


def downgrade() -> None:
    op.drop_column("product_categories", "featured_label")
