ALTER TABLE idempotency_keys
  ADD COLUMN lease_owner UUID,
  ADD COLUMN lease_until TIMESTAMPTZ;

ALTER TABLE idempotency_keys
  ADD CONSTRAINT idempotency_keys_lease_pair_check
  CHECK ((lease_owner IS NULL) = (lease_until IS NULL));

CREATE INDEX idempotency_keys_stale_operations
  ON idempotency_keys(lease_until)
  WHERE response_status = 0;
