diff --git a/app/schema.sql b/app/schema.sql index 7844c25..b0dbd98 100644 --- a/app/schema.sql +++ b/app/schema.sql @@ -581,3 +581,20 @@ CREATE TABLE IF NOT EXISTS dtf_local.machine_snoozes ( snoozed_by text NOT NULL, snoozed_at timestamptz NOT NULL DEFAULT now(), PRIMARY KEY(machine_id, alert, cycle_from) ); + +-- Orders generated before the print file was a PNG with its strips (item 13) +-- open blank in the 100% viewer. Those not approved yet are generated again, +-- once: the same layout, now as PNG with strips. An approved final, a +-- customer's correction or a cancelled order is left as it is. +DO $$ BEGIN + IF NOT EXISTS (SELECT 1 FROM dtf_local.migrations WHERE name='png-regenerate-v1') THEN + UPDATE dtf_local.print_files p SET status='pending', attempts=0, claimed_at=NULL, claim_token=NULL, + finished_at=NULL, upload_id=NULL, detail='{}' + FROM dtf_local.orders o + WHERE o.id=p.order_id AND o.state='rec' AND o.cancelled_at IS NULL + AND p.status='ready' AND NOT (p.detail ? 'format') + AND NOT EXISTS (SELECT 1 FROM dtf_local.order_files f WHERE f.order_id=p.order_id + AND f.item_index=p.item_index AND f.active); + INSERT INTO dtf_local.migrations VALUES('png-regenerate-v1'); + END IF; +END $$;