"""traceability and manual input become rules of the recipe Three settings that were nowhere: whether the lot and the serial are compulsory, and whether a value may be typed instead of read from the caliper. Until now lot and serial were optional everywhere and the keypad was always available, so a value that happens to be in tolerance could simply be entered by hand. Backfill: the two traceability flags start false, which is exactly today's behaviour. Manual input starts *true* on the recipes that already exist - the column default is false, so recipes written from now on are caliper-only, but flipping the ones already in use would stop a running line at the next measurement. Turning them off is a decision for whoever owns the recipe, taken in the editor, not a side effect of an upgrade. Revision ID: 009_recipe_rules Revises: 008_loop_events Create Date: 2026-07-28 """ from typing import Sequence, Union from alembic import op import sqlalchemy as sa revision: str = '009_recipe_rules' down_revision: Union[str, None] = '008_loop_events' branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: op.add_column( 'recipes', sa.Column( 'requires_lot', sa.Boolean(), nullable=False, server_default='0', ), ) op.add_column( 'recipes', sa.Column( 'requires_serial', sa.Boolean(), nullable=False, server_default='0', ), ) op.add_column( 'recipes', sa.Column( 'allow_manual_input', sa.Boolean(), nullable=False, server_default='0', ), ) # Recipes already in production keep the behaviour they were written under. op.execute("UPDATE recipes SET allow_manual_input = 1") def downgrade() -> None: op.drop_column('recipes', 'allow_manual_input') op.drop_column('recipes', 'requires_serial') op.drop_column('recipes', 'requires_lot')