"""code_shape_consumers — the CSS consumer map (milestone 302, note 2917)

Revision ID: 0086
Revises: 0085
Create Date: 2026-08-23

CSS is watched by name, by recipe, by token and by WHAT USES IT. This table
holds the fourth: CSS shape → the file whose markup names its class, with how
many times. Mechanical and recomputed by every coverage sync from the repo
archive; the analogue of code_shape_uses for styling. Cascades with the shape.
"""
import sqlalchemy as sa
from alembic import op

revision = "0086"
down_revision = "0085"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.create_table(
        "code_shape_consumers",
        sa.Column("id", sa.Integer(), primary_key=True),
        sa.Column("shape_id", sa.Integer(), sa.ForeignKey("code_shapes.id", ondelete="CASCADE"), nullable=False),
        sa.Column("path", sa.Text(), nullable=False),
        sa.Column("count", sa.Integer(), nullable=False, server_default="1"),
        sa.Column("basis", sa.Text(), nullable=False, server_default="template"),
        sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
        sa.UniqueConstraint("shape_id", "path", name="uq_code_shape_consumers_shape_path"),
    )


def downgrade() -> None:
    op.drop_table("code_shape_consumers")
