fix: align warning-case blocking semantics across reconcile paths

Co-authored-by: genichin <4282227+genichin@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-09-12 13:28:40 +00:00
committed by GitHub
co-authored by genichin
parent 45a5e4157d
commit 310b6f6dec
5 changed files with 63 additions and 13 deletions
@@ -1,7 +1,30 @@
-- REQ-123 / issue #83:
-- Preserve simultaneous warning causes by keying warnings per (slot_id, case_code).
-- NOTE: historical overwritten causes cannot be reconstructed from the prior
-- slot_id-only schema; this migration enables forward preservation only.
UPDATE slot_reconcile_warning
SET case_code = 'B'
WHERE case_code IS NULL OR case_code = '';
ALTER TABLE slot_reconcile_warning
ALTER COLUMN case_code SET NOT NULL;
DELETE FROM slot_reconcile_warning w
USING (
SELECT ctid, ROW_NUMBER() OVER (
PARTITION BY slot_id, case_code
ORDER BY updated_at DESC, created_at DESC, ctid DESC
) AS rn
FROM slot_reconcile_warning
) ranked
WHERE w.ctid = ranked.ctid
AND ranked.rn > 1;
ALTER TABLE slot_reconcile_warning
DROP CONSTRAINT IF EXISTS slot_reconcile_warning_pkey;
ALTER TABLE slot_reconcile_warning
ADD CONSTRAINT slot_reconcile_warning_pkey PRIMARY KEY (slot_id, case_code);
CREATE INDEX IF NOT EXISTS idx_slot_reconcile_warning_slot_id
ON slot_reconcile_warning (slot_id);