\set ON_ERROR_STOP on
begin;

do $$
declare
  updated int;
begin
  if not exists (select 1 from public.claims where id = 'e6ce4e36-15d2-53bc-8b74-dda0efc095c1'::uuid) then
    raise exception 'cross-surface packet requires Claim D % to exist before anchor update', 'e6ce4e36-15d2-53bc-8b74-dda0efc095c1';
  end if;

  if not exists (select 1 from public.sources where id = '9a0d2429-b98b-585a-980c-0176db7f9fe7'::uuid) then
    raise exception 'cross-surface packet requires approval source % to exist before anchor update', '9a0d2429-b98b-585a-980c-0176db7f9fe7';
  end if;

  update public.strategy_node_anchors
     set claim_id = 'e6ce4e36-15d2-53bc-8b74-dda0efc095c1'::uuid,
         weight = 0.85,
         note = 'Mapped rich proposal 14fa5ecc applied: active Leo policy now anchors to Claim D (internet finance is a candidate mechanism, not the telos) instead of the retired compressed internet-finance claim.'
   where id = '47f128a0-36c5-4b60-97d4-48c32fa48bc7'::uuid
     and from_node_id = '52bc4264-330e-489d-920c-a493fd2d985a'::uuid
     and anchor_role = 'justified_by'
     and claim_id = 'd0000000-0000-0000-0000-000000000005'::uuid;

  get diagnostics updated = row_count;
  if updated <> 1 then
    raise exception 'cross-surface anchor update affected % row(s), expected 1; anchor was not at old claim state', updated;
  end if;
end $$;

commit;
