"""The admin's featured pin (Stream AW2.2; the brief `.logs/planning/streams/AW2-featured.md`, D5).

Schema only: `featured BOOLEAN NOT NULL DEFAULT false` on `product_lines` and `product_variants`,
each with a partial index over the pinned rows (a handful among tens of thousands, so the read
that lists pins never scans the table). Not on `brands`: a pin names a bottle or a line of
bottles, never a house (working assumption 3). No backfill: nothing is pinned until a person
pins it through `app.cli featured pin`, which writes the ledger row the column materialises.

Why: rian's first factor for what is featured is an admin's pick. The pin orders every
featured list the record is already a comparison in; it never admits one and never labels it.

Revision ID: aw2c1d2e3f4a
Revises: aw3b1c2d3e4f
Create Date: 2026-09-19
"""

import sqlalchemy as sa

from alembic import op

revision = "aw2c1d2e3f4a"
down_revision = "aw3b1c2d3e4f"
branch_labels = None
depends_on = None

TABLES = ("product_lines", "product_variants")


def upgrade() -> None:
    for table in TABLES:
        op.add_column(table, sa.Column("featured", sa.Boolean(), nullable=False, server_default=sa.text("false")))
        op.create_index(f"ix_{table}_featured", table, ["id"], postgresql_where=sa.text("featured"))


def downgrade() -> None:
    for table in reversed(TABLES):
        op.drop_index(f"ix_{table}_featured", table_name=table)
        op.drop_column(table, "featured")
