fix: the repair of the missing parts raises each order's version, so the board and the folders see them at once
Some checks failed
Some checks failed
Tested on Postgres 17: only the orders before Imprimindo whose Prumo approved part of a film get the rest; orders approved by a person, printing, treated or with an old final are left alone. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -7,13 +7,18 @@ ALTER TABLE dtf_local.print_files ADD COLUMN IF NOT EXISTS generation integer NO
|
||||
-- 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);
|
||||
-- The order's version goes up, so the board and the folders see the new finals.
|
||||
WITH added AS (
|
||||
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)
|
||||
RETURNING order_id
|
||||
)
|
||||
UPDATE dtf_local.orders SET version=version+1, updated_at=now() WHERE id IN (SELECT order_id FROM added);
|
||||
|
||||
Reference in New Issue
Block a user