feat(tasks): il tipo di un task si dichiara, non si deduce
Punto 2 del documento modifiche del 28/07, prima richiesta di Menoncin. Il sistema distingueva un task di misura da uno documentale deducendolo: se aveva quote era una misura, altrimenti una nota. Conseguenza: un task di misura a cui le quote non erano ancora state inserite veniva trattato come nota, e il sistema si comportava in modo diverso a seconda di quanto fosse completa la ricetta. Nuovo campo task_type su recipe_tasks (migrazione 007) con nota, misura e disegno, piu' xf_compare e camera_measure gia' nell'enum: allargare un enum MySQL piu' avanti e' un ALTER su tabella viva, e non costa nulla prevederli adesso. Il backfill riproduce la classificazione che era a schermo, cosi' nessuna ricetta cambia comportamento all'aggiornamento: i task con quote diventano 'measure'; quelli senza quote ma con un disegno allegato diventano 'drawing' e non 'note', perche' e' gia' cio' che mostravano - chiamarli note sarebbe stato l'unico punto in cui questa migrazione cambiava le carte in tavola. Il tipo viene copiato esplicitamente nel copy-on-write del versioning: una nuova versione che lo perdesse riclassificherebbe in silenzio tutti i task alla prima modifica di una ricetta. Il task "Technical Drawing" creato d'ufficio quando si carica un disegno su una ricetta senza task nasce come 'drawing'. Lato operatore decide ora il tipo, non il conteggio delle quote: fermo linea, fine produzione, avvio produzione e la barra di produzione seguono il tipo. Dove servono davvero delle quote da mostrare - elenco marker, tastierino, fine ciclo misura - resta anche il controllo che ce ne sia almeno una, e un task di misura ancora privo di quote lo dichiara invece di somigliare a una nota. Nella lista task compare il tipo, cosi' si vede prima di aprire. La 007 e' stata eseguita su SQLite usa e getta con tre righe costruite apposta - una con quote, una col solo disegno, una nota secca - e il backfill le classifica come atteso. Il backfill girera' sui dati reali del cliente, provarlo a mano non bastava. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
"""add an explicit type to recipe tasks
|
||||
|
||||
Until now the kind of a task was deduced: quotes present meant a measurement,
|
||||
otherwise a note. A measurement task whose quotes had not been entered yet was
|
||||
therefore treated as a note - the system behaved differently depending on how
|
||||
complete the recipe happened to be.
|
||||
|
||||
Existing rows are classified by the rule that was in force, so nothing changes
|
||||
behaviour on upgrade: tasks with quotes become 'measure'. Tasks with no quotes but
|
||||
a drawing attached become 'drawing' rather than 'note' - that is what they already
|
||||
displayed as, and calling them notes would be the one place this migration did
|
||||
change behaviour.
|
||||
|
||||
Revision ID: 007_task_type
|
||||
Revises: 006_measurement_run
|
||||
Create Date: 2026-07-28
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
revision: str = '007_task_type'
|
||||
down_revision: Union[str, None] = '006_measurement_run'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
TASK_TYPES = ('note', 'measure', 'drawing', 'xf_compare', 'camera_measure')
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column(
|
||||
'recipe_tasks',
|
||||
sa.Column(
|
||||
'task_type',
|
||||
sa.Enum(*TASK_TYPES, name='task_type_enum'),
|
||||
nullable=False,
|
||||
server_default='note',
|
||||
),
|
||||
)
|
||||
op.create_index('ix_recipe_tasks_task_type', 'recipe_tasks', ['task_type'])
|
||||
|
||||
# Backfill by the rule the frontend used, so no recipe changes behaviour.
|
||||
op.execute(
|
||||
"""
|
||||
UPDATE recipe_tasks
|
||||
SET task_type = 'measure'
|
||||
WHERE id IN (SELECT DISTINCT task_id FROM recipe_subtasks)
|
||||
"""
|
||||
)
|
||||
op.execute(
|
||||
"""
|
||||
UPDATE recipe_tasks
|
||||
SET task_type = 'drawing'
|
||||
WHERE task_type = 'note'
|
||||
AND file_path IS NOT NULL
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index('ix_recipe_tasks_task_type', table_name='recipe_tasks')
|
||||
op.drop_column('recipe_tasks', 'task_type')
|
||||
Reference in New Issue
Block a user