\set ON_ERROR_STOP on
-- Emergency rollback for governance/concept generated rows only.
-- Drops generated schema only when the generated tables are empty after row delete.
begin;

delete from public.claim_governance_gate_links
where id in (select id from (values
    ('1f81e105-af5e-5db8-a7be-08cc6cc4e13a'::uuid),
    ('af04a87e-c1da-57e9-b11c-60d79daa5648'::uuid)
  ) as v(id));

delete from public.claim_concept_map_links
where id = 'af4ce1b9-db03-5bde-a21b-0e16ca0f48b8'::uuid;

delete from public.concept_maps
where id = 'f013126c-0937-5bc8-b021-9697e59057d0'::uuid;

do $$
begin
  if to_regclass('public.claim_governance_gate_links') is not null
     and not exists (select 1 from public.claim_governance_gate_links) then
    drop table public.claim_governance_gate_links;
  end if;

  if to_regclass('public.claim_concept_map_links') is not null
     and not exists (select 1 from public.claim_concept_map_links) then
    drop table public.claim_concept_map_links;
  end if;

  if to_regclass('public.concept_maps') is not null
     and not exists (select 1 from public.concept_maps) then
    drop table public.concept_maps;
  end if;
end $$;

commit;
