Files
dtf-system/app/migrations/202611271400_print-file-version.sql
Cauê Faleiros b027bb5013
Some checks failed
Build and deploy / Validate source (push) Successful in 16s
Build and deploy / Publish images (push) Has been cancelled
Build and deploy / Integration suite on a real stack (push) Has been cancelled
Build and deploy / Secret scan and release gate (push) Has been cancelled
fix: Prova OK approves every part of a film, and "Gerar de novo" names the new files with a version (#114, #128, #130)
The proof's approval took the print file's first upload as the final, so the
other parts of a film in parts never reached Arte conferida or the hot folder
and were downloaded by hand. It now approves every part, and adds the missing
ones to a first part already approved. A one-off migration completes the
open orders still before Imprimindo. Generated again, the files are named
DTF-130-v2-item-1-p2.png, as Marcus asked, so the FlexiPRINT queue and the
Hoson list never take them for the first ones.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-27 12:25:23 -03:00

20 lines
1.4 KiB
SQL

-- "Gerar de novo" names the new files with a version (Marcus, 2026-11-27,
-- #130): DTF-130-v2-item-1-p2.png, so neither the Kanban, the FlexiPRINT
-- queue nor the Hoson list mixes them up with the first ones.
ALTER TABLE dtf_local.print_files ADD COLUMN IF NOT EXISTS generation integer NOT NULL DEFAULT 1;
-- A Prova OK approved only the first part of a film in parts (the print
-- file's first upload), so the other parts never reached the folders (#114,
-- #128, #130). For the orders still before Imprimindo, the missing parts join
-- the parts the Prumo already approved.
INSERT INTO dtf_local.order_files(id,order_id,upload_id,item_index,kind,note,created_by)
SELECT gen_random_uuid(), p.order_id, p.upload_id, p.item_index, 'final', 'Parte completada (prova)', 'Prumo'
FROM dtf_local.print_parts p JOIN dtf_local.orders o ON o.id=p.order_id
WHERE o.state IN ('rec','tra') AND o.cancelled_at IS NULL AND o.parent_id IS NULL
AND EXISTS (SELECT 1 FROM dtf_local.order_files f JOIN dtf_local.print_parts q
ON q.order_id=f.order_id AND q.item_index=f.item_index AND q.upload_id=f.upload_id
WHERE f.order_id=p.order_id AND f.item_index=p.item_index AND f.kind='final' AND f.active
AND f.created_by='Prumo')
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.upload_id=p.upload_id);