From 065a224dc7171f10a3c0c870d11c96e077ec1edc Mon Sep 17 00:00:00 2001 From: Xiaoyang Han Date: Thu, 8 Oct 2026 10:19:42 +0800 Subject: [PATCH] Parenthesize chunk retention CASE expressions in PL/pgSQL IF guards Database bootstrap currently fails with PostgreSQL 42601 at Original(10355): the first unparenthesized CASE in a PL/pgSQL IF exposes its internal THEN as the end of the IF condition. Parenthesize that CASE and the identical later map guard expression. Preserve both 512 MiB capacity checks, state-dependent 256 KiB/1 MiB reserves, error messages and every other migration byte. Exact original source-offset and whole-file inverse proofs plus whitespace and unchanged-tree checks pass. The cancelled native run has no completed test summary; this candidate has not executed SQL or native tests. --- .../migration/m20261008_000300_chunk_map_retention.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jupiter/migration/m20261008_000300_chunk_map_retention.sql b/src/jupiter/migration/m20261008_000300_chunk_map_retention.sql index 46a75aa3..f967d440 100644 --- a/src/jupiter/migration/m20261008_000300_chunk_map_retention.sql +++ b/src/jupiter/migration/m20261008_000300_chunk_map_retention.sql @@ -152,7 +152,7 @@ BEGIN IF TG_OP='DELETE' OR TG_OP='TRUNCATE' THEN RAISE EXCEPTION 'chunk receipt generations and collection history are retained'; END IF; - IF mst2_chunk_retention_bytes()+CASE WHEN NEW.state IN ('DELETING','APPLIED') THEN 262144 ELSE 1048576 END>536870912 THEN + IF mst2_chunk_retention_bytes()+(CASE WHEN NEW.state IN ('DELETING','APPLIED') THEN 262144 ELSE 1048576 END)>536870912 THEN RAISE EXCEPTION 'chunk receipt mutation lacks actual durable byte headroom'; END IF; IF TG_OP='UPDATE' AND (NEW.receipt_key IS DISTINCT FROM OLD.receipt_key OR NEW.source_id IS DISTINCT FROM OLD.source_id @@ -244,7 +244,7 @@ BEGIN IF NOT permitted THEN RAISE EXCEPTION 'map lifetime deletion lacks exact reader-free collection claim'; END IF; RETURN OLD; END IF; - IF mst2_chunk_retention_bytes()+CASE WHEN NEW.state='DELETING' THEN 262144 ELSE 1048576 END>536870912 THEN + IF mst2_chunk_retention_bytes()+(CASE WHEN NEW.state='DELETING' THEN 262144 ELSE 1048576 END)>536870912 THEN RAISE EXCEPTION 'chunk map lifetime mutation lacks actual durable byte headroom'; END IF; IF TG_OP='UPDATE' AND (NEW.map_id IS DISTINCT FROM OLD.map_id OR NEW.generation IS DISTINCT FROM OLD.generation