"""Phase 12.2 — QR Menu & QR Ordering schema."""
from alembic import op
import sqlalchemy as sa
from app.core.database import Base
import app.models  # noqa: F401

revision = "0003_phase_122_qr_menu_ordering"
down_revision = "0002_phase_121_menu_catalog"
branch_labels = None
depends_on = None


def upgrade():
    bind = op.get_bind()
    # Create new QR / ordering tables from metadata (additive)
    Base.metadata.create_all(bind=bind)


def downgrade():
    bind = op.get_bind()
    for table in (
        "cart_lines",
        "carts",
        "qr_ordering_sessions",
        "qr_menu_sessions",
        "qr_codes",
    ):
        if sa.inspect(bind).has_table(table):
            op.drop_table(table)
