From 0252728a00fa142193f550b658cccc2cc1beee23 Mon Sep 17 00:00:00 2001 From: Brad Seiler Date: Mon, 9 Nov 2026 15:41:41 -0800 Subject: [PATCH] fix(db): fail invite repair when validation remains nonzero Co-authored-by: Honor Signed-off-by: Brad Seiler --- .../src/store/relay_invite/upgrade_postgres_tests.rs | 7 +------ scripts/maintenance/backfill_invite_revocations.sql | 12 ++++++++++-- 2 files changed, 11 insertions(+), 8 deletions(-) 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 7db96bc68b..6e864091e8 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 @@ -446,12 +446,7 @@ pub(super) async fn run_invite_repair_script(pool: &PgPool) -> String { String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr), ); - let stdout = String::from_utf8_lossy(&output.stdout).into_owned(); - assert!( - stdout.lines().any(|line| line.trim() == "0"), - "repair validation did not return zero unrepaired invites:\n{stdout}" - ); - stdout + String::from_utf8_lossy(&output.stdout).into_owned() } async fn invite_revocation_state(pool: &PgPool) -> Vec<(Uuid, Option>, bool)> { diff --git a/scripts/maintenance/backfill_invite_revocations.sql b/scripts/maintenance/backfill_invite_revocations.sql index 0636422ea1..f9deca5b52 100644 --- a/scripts/maintenance/backfill_invite_revocations.sql +++ b/scripts/maintenance/backfill_invite_revocations.sql @@ -148,7 +148,7 @@ $$; -- Expected result: 0. Every legacy marker in an active community has been -- examined and cleared; every currently active ban has durably revoked its -- invite. Markers in fenced communities remain for a later repair run. -SELECT count(*) AS unrepaired_invites +SELECT count(*) AS unrepaired_invites, count(*) = 0 AS repair_complete FROM relay_invites AS invite JOIN communities AS community ON community.id = invite.community_id CROSS JOIN LATERAL ( @@ -182,4 +182,12 @@ WHERE community.deletion_state = 'active' OR restriction.ban_expires_at > clock_timestamp()) ) ) - ); + )\gset +\echo unrepaired_invites +\echo :unrepaired_invites +\if :repair_complete +\else +DO $$ BEGIN + RAISE EXCEPTION 'invite repair incomplete; keep admission closed and rerun'; +END $$; +\endif