do $$
declare
    current_status text;
    event_count integer;
begin
    select status into strict current_status
    from shipments
    where external_id = 'shipment-100';

    if current_status <> 'in_transit' then
        raise exception 'shipment-100 has unexpected status %', current_status;
    end if;

    select count(*) into event_count
    from shipment_events e
    join shipments s on s.id = e.shipment_id
    where s.external_id = 'shipment-100';

    if event_count <> 2 then
        raise exception 'shipment-100 has % events, expected 2', event_count;
    end if;
end
$$;
