Skip to content

fix(db): fail boot loudly on legacy single-tenant audit_log schema (#4919) - #5035

Open
yippietheproducer wants to merge 1 commit into
block:mainfrom
yippietheproducer:pr/4919-audit-preflight
Open

fix(db): fail boot loudly on legacy single-tenant audit_log schema (#4919)#5035
yippietheproducer wants to merge 1 commit into
block:mainfrom
yippietheproducer:pr/4919-audit-preflight

Conversation

@yippietheproducer

Copy link
Copy Markdown

Fixes #4919.

Problem

A legacy single-tenant audit_log (pre multi-tenant rewrite) has no
community_id column, so every audit write errors with
column "community_id" does not exist while the relay keeps serving
traffic — a tamper-evident audit chain silently stops recording in
production, and the per-event ERROR line is easy to miss.

The legacy→multi-tenant cutover is deliberately an operator script
(scripts/cutover/1321_backfill_default_community.sql), not startup
migration state (see the stance in crates/buzz-db/src/migration.rs and
the discussion in the issue), so a 0028 migration was not the fix.

Fix

Adds reject_legacy_audit_log_shape() — a startup preflight that detects
the legacy shape and fails the boot loudly with the operator path,
instead of the silent per-event ERROR spam.

  • Runs on both the migrating (run_migrations) and non-migrating
    (main.rs, BUZZ_AUTO_MIGRATE defaults to off) startup paths.
  • The check is a live table-shape probe, not a _sqlx_migrations version
    check
    : affected deployments reached this state with no migration record
    of audit_log at all, so no version predicate would have caught them.
  • Mirrors the existing reject_legacy_nip_rs_cardinality_ambiguity
    fail-closed preflight in the same file.

Verification

  • cargo check -p buzz-db -p buzz-relay — clean, zero warnings
  • New DB-backed regression test (fresh schema passes, legacy shape blocks
    with an actionable message naming community_id + the cutover path,
    absent table passes)
  • Full buzz-db DB-backed suite: 152 passed / 2 failed — the 2 failures
    (relay_members owner-limit tests) are pre-existing, reproduced on the
    clean tree without this change

@yippietheproducer
yippietheproducer requested a review from a team as a code owner August 6, 2026 10:16
…lock#4919)

A legacy audit_log (pre multi-tenant rewrite) has no community_id column,
so every audit write ERRORs with `column "community_id" does not exist`
while the relay keeps serving traffic — a tamper-evident audit chain
silently stops recording in production, and the per-event ERROR line is
easy to miss. The legacy->multi-tenant cutover is deliberately an operator
script (scripts/cutover/1321_backfill_default_community.sql), not startup
migration state, so instead of a (stance-rejected) 0028 migration this adds
a startup preflight that detects the legacy shape and fails the boot loudly
with the operator path.

Runs on both the migrating and non-migrating startup paths. The check is a
live table-shape probe, not a _sqlx_migrations version check: affected
deployments reached this state with no migration record of audit_log at
all (the table predates the migration chain), so no version predicate
would catch them. Covered by a DB-backed regression test (fresh schema
passes, legacy shape blocks with an actionable message, absent table
passes).

Signed-off-by: mmaciejek <chacinskimaciej@gmail.com>
@yippietheproducer
yippietheproducer force-pushed the pr/4919-audit-preflight branch from 0924218 to 94f0e8a Compare August 6, 2026 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing ALTER TABLE migration for audit_log multi-tenant schema (breaks existing deployments upgrading to 0.2.0)

1 participant