\set ON_ERROR_STOP on
-- Emergency rollback for Rio strategy-context generated rows only.
-- Run only before later production data depends on these generated rows.
begin;

do $$
declare
  deleted_anchors int;
  deleted_nodes int;
begin
  delete from public.strategy_node_anchors
  where id in (select id from (values
    ('3a0e2228-a74f-5971-b467-fb527ccdfb37'::uuid),
    ('3f7a9f84-eb2e-5d94-9ca4-afc3bad47f96'::uuid),
    ('d18eaa71-d458-53cc-baac-e5306a1779e2'::uuid),
    ('33d9eb08-c9c2-5e2d-a9a7-3d7f1b5f0f0c'::uuid),
    ('3b2a8908-120d-59a5-bbd5-d2711a123aa3'::uuid)
  ) as v(id));

  get diagnostics deleted_anchors = row_count;
  if deleted_anchors <> 5 then
    raise exception 'Rio strategy rollback deleted % strategy anchor row(s), expected 5', deleted_anchors;
  end if;

  delete from public.strategy_nodes
  where id in (select id from (values
    ('4f3e3d77-50fa-520a-8c8b-5a4269d94a9b'::uuid),
    ('063528a6-a07c-5c14-abdf-dc12a0b10fcf'::uuid)
  ) as v(id));

  get diagnostics deleted_nodes = row_count;
  if deleted_nodes <> 2 then
    raise exception 'Rio strategy rollback deleted % strategy node row(s), expected 2', deleted_nodes;
  end if;
end $$;

commit;
