-- rollback for STEP_044M 20260709-143054
BEGIN;

WITH v(peer_id,tunnel_ip,last_tx_packets,last_tx_bytes,last_rx_packets,last_rx_bytes,state,last_activity_at,updated_at,reason) AS (
VALUES
('376dfa07-0ba4-4182-af39-389a2cb3badd'::uuid,'10.253.1.10/32'::inet,0::bigint,0::bigint,0::bigint,0::bigint,'idle'::text,NULL::timestamptz,'2026-07-09 13:18:38.59577+00'::timestamptz,'bootstrap_from_existing_vm100_selector'::text),
('cb533a1a-7070-416d-9272-846327545060'::uuid,'10.253.1.11/32'::inet,0::bigint,0::bigint,0::bigint,0::bigint,'idle'::text,NULL::timestamptz,'2026-07-09 13:18:38.59577+00'::timestamptz,'bootstrap_from_existing_vm100_selector'::text),
('a3cbe3b5-8416-4847-b5ee-21f42359b465'::uuid,'10.253.1.12/32'::inet,0::bigint,0::bigint,0::bigint,0::bigint,'idle'::text,NULL::timestamptz,'2026-07-09 13:18:38.59577+00'::timestamptz,'bootstrap_from_existing_vm100_selector'::text),
('219a1f63-ec47-4f72-9663-c1a17d82301e'::uuid,'10.253.1.13/32'::inet,0::bigint,0::bigint,0::bigint,0::bigint,'idle'::text,NULL::timestamptz,'2026-07-09 13:18:38.59577+00'::timestamptz,'bootstrap_from_existing_vm100_selector'::text),
('e4adcfa1-6fbc-4471-b66b-8d7837f35f9d'::uuid,'10.253.1.14/32'::inet,0::bigint,0::bigint,0::bigint,0::bigint,'idle'::text,NULL::timestamptz,'2026-07-09 13:18:38.59577+00'::timestamptz,'bootstrap_from_existing_vm100_selector'::text)
),
updated AS (
  UPDATE public.peer_egress_leases AS l
  SET
    last_tx_packets = v.last_tx_packets,
    last_tx_bytes = v.last_tx_bytes,
    last_rx_packets = v.last_rx_packets,
    last_rx_bytes = v.last_rx_bytes,
    state = v.state,
    last_activity_at = v.last_activity_at,
    updated_at = v.updated_at,
    reason = v.reason
  FROM v
  WHERE l.peer_id = v.peer_id
    AND l.tunnel_ip = v.tunnel_ip
  RETURNING l.peer_id
)
SELECT 'rollback_rows', count(*)::text FROM updated;

COMMIT;
