"""add product labels and stickers

Revision ID: 20251107_121500_add_labels_stickers
Revises: 20251107_090500_snapshot_to_db
Create Date: 2025-11-07T12:15:00.000000
"""
from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = "20251107_121500_labels_stickers"
down_revision = "20251107_090500_snapshot_to_db"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.create_table(
        "product_labels",
        sa.Column("id", sa.Integer(), primary_key=True),
        sa.Column("product_id", sa.Integer(), sa.ForeignKey("products.id", ondelete="CASCADE"), nullable=False),
        sa.Column("name", sa.String(length=255), nullable=False),
    )
    op.create_index("ix_product_labels_product_id", "product_labels", ["product_id"], unique=False)
    op.create_index("ix_product_labels_name", "product_labels", ["name"], unique=False)
    op.create_unique_constraint(
        "uq_product_labels_product_name", "product_labels", ["product_id", "name"]
    )

    op.create_table(
        "product_stickers",
        sa.Column("id", sa.Integer(), primary_key=True),
        sa.Column("product_id", sa.Integer(), sa.ForeignKey("products.id", ondelete="CASCADE"), nullable=False),
        sa.Column("name", sa.String(length=255), nullable=False),
    )
    op.create_index("ix_product_stickers_product_id", "product_stickers", ["product_id"], unique=False)
    op.create_index("ix_product_stickers_name", "product_stickers", ["name"], unique=False)
    op.create_unique_constraint(
        "uq_product_stickers_product_name", "product_stickers", ["product_id", "name"]
    )


def downgrade() -> None:
    op.drop_constraint("uq_product_stickers_product_name", "product_stickers", type_="unique")
    op.drop_index("ix_product_stickers_name", table_name="product_stickers")
    op.drop_index("ix_product_stickers_product_id", table_name="product_stickers")
    op.drop_table("product_stickers")

    op.drop_constraint("uq_product_labels_product_name", "product_labels", type_="unique")
    op.drop_index("ix_product_labels_name", table_name="product_labels")
    op.drop_index("ix_product_labels_product_id", table_name="product_labels")
    op.drop_table("product_labels")
