\set ON_ERROR_STOP on
-- Emergency rollback for the mapped generated rows only.
-- Run only before any later production data depends on these generated rows.
begin;

delete from public.claim_evidence ce
using (values
    ('004195cc-ab62-526c-90fb-51cb0f826ec0'::uuid, 'f80c01fe-63bb-5ccf-9bdd-744bab0e9163'::uuid, 'illustrates'::evidence_role),
    ('004195cc-ab62-526c-90fb-51cb0f826ec0'::uuid, '3a57238c-ca31-5fe1-bece-e5fb2f174e32'::uuid, 'grounds'::evidence_role),
    ('004195cc-ab62-526c-90fb-51cb0f826ec0'::uuid, '8f952541-5f12-5f24-88b3-21e7842163a1'::uuid, 'grounds'::evidence_role),
    ('004195cc-ab62-526c-90fb-51cb0f826ec0'::uuid, '9a0d2429-b98b-585a-980c-0176db7f9fe7'::uuid, 'grounds'::evidence_role),
    ('d009dfc4-9755-58a7-affb-80e3e842a775'::uuid, '9fd61e7e-d5cb-5904-b5c2-a539946f7c96'::uuid, 'illustrates'::evidence_role),
    ('d009dfc4-9755-58a7-affb-80e3e842a775'::uuid, '33fadb51-0bd8-5f2d-87fe-758a3dd7fac0'::uuid, 'grounds'::evidence_role),
    ('67003e10-e1ee-5905-8b51-1b0cb263ec11'::uuid, '6c3c26c1-39bc-58e5-8c76-28b5712420ce'::uuid, 'illustrates'::evidence_role),
    ('67003e10-e1ee-5905-8b51-1b0cb263ec11'::uuid, '9a0d2429-b98b-585a-980c-0176db7f9fe7'::uuid, 'grounds'::evidence_role),
    ('e6ce4e36-15d2-53bc-8b74-dda0efc095c1'::uuid, '997e5e58-b20d-560a-a73a-eaa4bff1dc3e'::uuid, 'illustrates'::evidence_role),
    ('e6ce4e36-15d2-53bc-8b74-dda0efc095c1'::uuid, '8f952541-5f12-5f24-88b3-21e7842163a1'::uuid, 'grounds'::evidence_role),
    ('e6ce4e36-15d2-53bc-8b74-dda0efc095c1'::uuid, '9a0d2429-b98b-585a-980c-0176db7f9fe7'::uuid, 'grounds'::evidence_role),
    ('9bcf7e6b-4e98-52b1-91ef-96cfc15e3df0'::uuid, 'a3cba49b-7016-5f42-9af6-041f12371a24'::uuid, 'illustrates'::evidence_role),
    ('9bcf7e6b-4e98-52b1-91ef-96cfc15e3df0'::uuid, '4787c38e-74cb-5bf5-93e1-0cc9c290684c'::uuid, 'grounds'::evidence_role),
    ('62e82ee8-b204-573b-9707-eb5d832b9d9e'::uuid, 'eea07732-c65d-5db6-88d6-1ab08511eca6'::uuid, 'illustrates'::evidence_role),
    ('62e82ee8-b204-573b-9707-eb5d832b9d9e'::uuid, '4787c38e-74cb-5bf5-93e1-0cc9c290684c'::uuid, 'grounds'::evidence_role),
    ('cd8daac8-039c-5349-9c50-02f622e73b03'::uuid, '244a4c38-86e5-5910-91f4-6d71529e9b31'::uuid, 'illustrates'::evidence_role),
    ('cd8daac8-039c-5349-9c50-02f622e73b03'::uuid, '4cc0c7ee-2166-5cae-9065-ea226fa2be5b'::uuid, 'grounds'::evidence_role)
  ) as v(claim_id, source_id, role)
where ce.claim_id = v.claim_id and ce.source_id = v.source_id and ce.role = v.role;

delete from public.claim_edges e
using (values
    ('004195cc-ab62-526c-90fb-51cb0f826ec0'::uuid, 'd0000000-0000-0000-0000-000000000005'::uuid, 'supersedes'::edge_type),
    ('d009dfc4-9755-58a7-affb-80e3e842a775'::uuid, 'd0000000-0000-0000-0000-000000000005'::uuid, 'supersedes'::edge_type),
    ('67003e10-e1ee-5905-8b51-1b0cb263ec11'::uuid, 'd0000000-0000-0000-0000-000000000005'::uuid, 'supersedes'::edge_type),
    ('e6ce4e36-15d2-53bc-8b74-dda0efc095c1'::uuid, 'd0000000-0000-0000-0000-000000000005'::uuid, 'supersedes'::edge_type),
    ('d009dfc4-9755-58a7-affb-80e3e842a775'::uuid, '7da4851c-0aac-4084-a99f-baeeeb3aa23e'::uuid, 'relates'::edge_type),
    ('67003e10-e1ee-5905-8b51-1b0cb263ec11'::uuid, 'd009dfc4-9755-58a7-affb-80e3e842a775'::uuid, 'requires'::edge_type),
    ('e6ce4e36-15d2-53bc-8b74-dda0efc095c1'::uuid, '67003e10-e1ee-5905-8b51-1b0cb263ec11'::uuid, 'constrains'::edge_type),
    ('62e82ee8-b204-573b-9707-eb5d832b9d9e'::uuid, 'cd8daac8-039c-5349-9c50-02f622e73b03'::uuid, 'derives_from'::edge_type),
    ('62e82ee8-b204-573b-9707-eb5d832b9d9e'::uuid, 'c0000000-0000-0000-0000-00000000000c'::uuid, 'relates'::edge_type),
    ('cd8daac8-039c-5349-9c50-02f622e73b03'::uuid, '7da4851c-0aac-4084-a99f-baeeeb3aa23e'::uuid, 'supersedes'::edge_type),
    ('cd8daac8-039c-5349-9c50-02f622e73b03'::uuid, '62e82ee8-b204-573b-9707-eb5d832b9d9e'::uuid, 'supports'::edge_type)
  ) as v(from_claim, to_claim, edge_type)
where e.from_claim = v.from_claim and e.to_claim = v.to_claim and e.edge_type = v.edge_type;

update public.claims
set superseded_by = null,
    updated_at = now()
where superseded_by in (select id from (values
    ('004195cc-ab62-526c-90fb-51cb0f826ec0'::uuid),
    ('d009dfc4-9755-58a7-affb-80e3e842a775'::uuid),
    ('67003e10-e1ee-5905-8b51-1b0cb263ec11'::uuid),
    ('e6ce4e36-15d2-53bc-8b74-dda0efc095c1'::uuid),
    ('9bcf7e6b-4e98-52b1-91ef-96cfc15e3df0'::uuid),
    ('62e82ee8-b204-573b-9707-eb5d832b9d9e'::uuid),
    ('cd8daac8-039c-5349-9c50-02f622e73b03'::uuid)
  ) as v(id));

delete from public.sources
where id in (select id from (values
    ('9a0d2429-b98b-585a-980c-0176db7f9fe7'::uuid),
    ('87f49cf0-5516-5aef-8ed9-f69292917d32'::uuid),
    ('33fadb51-0bd8-5f2d-87fe-758a3dd7fac0'::uuid),
    ('3a57238c-ca31-5fe1-bece-e5fb2f174e32'::uuid),
    ('8f952541-5f12-5f24-88b3-21e7842163a1'::uuid),
    ('f80c01fe-63bb-5ccf-9bdd-744bab0e9163'::uuid),
    ('9fd61e7e-d5cb-5904-b5c2-a539946f7c96'::uuid),
    ('6c3c26c1-39bc-58e5-8c76-28b5712420ce'::uuid),
    ('997e5e58-b20d-560a-a73a-eaa4bff1dc3e'::uuid),
    ('703fdfaf-22c9-5f5b-8d29-cf238d5e156f'::uuid),
    ('4787c38e-74cb-5bf5-93e1-0cc9c290684c'::uuid),
    ('4cc0c7ee-2166-5cae-9065-ea226fa2be5b'::uuid),
    ('a3cba49b-7016-5f42-9af6-041f12371a24'::uuid),
    ('eea07732-c65d-5db6-88d6-1ab08511eca6'::uuid),
    ('244a4c38-86e5-5910-91f4-6d71529e9b31'::uuid)
  ) as v(id));

delete from public.claims
where id in (select id from (values
    ('004195cc-ab62-526c-90fb-51cb0f826ec0'::uuid),
    ('d009dfc4-9755-58a7-affb-80e3e842a775'::uuid),
    ('67003e10-e1ee-5905-8b51-1b0cb263ec11'::uuid),
    ('e6ce4e36-15d2-53bc-8b74-dda0efc095c1'::uuid),
    ('9bcf7e6b-4e98-52b1-91ef-96cfc15e3df0'::uuid),
    ('62e82ee8-b204-573b-9707-eb5d832b9d9e'::uuid),
    ('cd8daac8-039c-5349-9c50-02f622e73b03'::uuid)
  ) as v(id));

commit;
