diff --git a/crates/buzz-db/src/store/relay_invite/upgrade_postgres_tests.rs b/crates/buzz-db/src/store/relay_invite/upgrade_postgres_tests.rs index e7051d3825..7db96bc68b 100644 --- a/crates/buzz-db/src/store/relay_invite/upgrade_postgres_tests.rs +++ b/crates/buzz-db/src/store/relay_invite/upgrade_postgres_tests.rs @@ -189,8 +189,13 @@ async fn legacy_fixture() -> (PgPool, Vec) { let issuer = [1u8; 32]; let mut cases = Vec::new(); + // Exercise cached successor lookups and the smallest valid UUID. for index in 0u8..12 { - let community = Uuid::new_v4(); + let community = if index == 0 { + Uuid::nil() + } else { + Uuid::new_v4() + }; sqlx::query("INSERT INTO communities (id, host) VALUES ($1, $2)") .bind(community) .bind(format!("upgrade-{index}-{community}.example")) diff --git a/scripts/maintenance/backfill_invite_revocations.sql b/scripts/maintenance/backfill_invite_revocations.sql index 3d42bd7ae0..0636422ea1 100644 --- a/scripts/maintenance/backfill_invite_revocations.sql +++ b/scripts/maintenance/backfill_invite_revocations.sql @@ -34,11 +34,18 @@ DECLARE affected BIGINT; BEGIN LOOP - SELECT id INTO target_community - FROM communities - WHERE last_community IS NULL OR id > last_community - ORDER BY id - LIMIT 1; + IF last_community IS NULL THEN + SELECT id INTO target_community + FROM communities + ORDER BY id + LIMIT 1; + ELSE + SELECT id INTO target_community + FROM communities + WHERE id > last_community + ORDER BY id + LIMIT 1; + END IF; EXIT WHEN NOT FOUND; last_community := target_community;