Files
buzz/crates
ravarora2 2c28e07133 BUZZ-413: Add user deletion fence storage (#8632)
## Summary

Add storage and lock helpers for the first user-deletion fencing PR. No
serving handler or deletion worker calls these helpers yet, so this does
not block users or enable real deletion.

The operator-global `user_deletion_fences` table stores global user
restrictions and community-scoped agent restrictions. Community and
profile deletion retain these rows unchanged. `scope_community_id`
records a restriction's scope; it does not make the row community-owned.

The helpers use the caller's transaction, stable identity lock keys,
ordered shared/exclusive locks, and indexed lookups. Inserts preserve
the original request and owner on retry and reject conflicting
provenance. Inserts validate the current worker lease and approved
inventory through the existing entity-deletion guards. Callers must
still verify that the target identities and agent ownership belong to
the request.

This is an additive schema expansion with a five-second migration lock
timeout. It adds no database triggers, functions, foreign keys, or
backfills. Both schema sources and operator-global registrations are
updated. The unused request-ID index was removed. The existing
community-deletion catalog and purge logic are unchanged. Tests cover
live schema parity, concurrency, rollback, and retention through the
existing purge and verification functions.

### Related issue

Part of
[BUZZ-413](https://linear.app/squareup/issue/BUZZ-413/gate-user-and-owned-agent-activity).
This is the storage foundation; serving checks and real workflow
handlers follow separately. No duplicate fence-storage PR found.

### Testing

No manual app testing: these utilities have no application callers yet.
Local PostgreSQL validation uses an isolated test container and the
repository's per-test database runner.

Passed 84 selected PostgreSQL tests covering fence authorization,
concurrent inserts, schema parity, retention, community deletion,
entity-deletion storage, and user discovery. The authorization
regression also failed as expected when the insertion guard was
temporarily removed; the guard was restored before the final run.

Command: `scripts/postgres-test-run.sh -p buzz-db --lib -E
'test(/user_deletion_fences/) | test(/admin_schema_parity_between/) |
test(/^store::deletion::postgres_tests::/) |
test(/^store::entity_deletion::postgres_tests::/) |
test(/^store::user_deletion::/)'` with the local test PostgreSQL
connection and `PG_BIN_DIR` configured.

The full `just test` run had one failure:
`composition_tests::composition_log_does_not_leak_issuer_url` missed an
expected log message. The same compiled test passed when rerun alone. No
relay logging code is changed by this PR.

The full local `just ci` run and all normal pre-push hooks passed on the
updated branch.

Generated with Codex

---------

Signed-off-by: Ravneet Arora <rarora@squareup.com>
2026-10-28 14:36:17 -04:00
..