← Back to Pull requests

fix(wallet): unblock production deploys — wallet DVA writer migration ALTER ROLE (42501) #4457

Open
unknown opened this pull request with 552 lines diff across 6 files
View on GitHub
unknown unknown commented on Nov 22, 2026 20:16 UTC
Author

What is broken

Production deploys have been stopped since #4441 merged. Every Deploy run on main fails in the db-migrations job, step "Apply remaining pending migrations via Management API", so the run never reaches deploy-production. Runs for 4096d6a357 and 5065712f44 both failed this way.

The failing migration is supabase/migrations/20261122064203_wallet_dva_restricted_writer.sql. From the job log (run 45046263526, job db-migrations):

→ applying:        20261122064203  wallet_dva_restricted_writer
##[error]Supabase query did not succeed; aborting before recording the migration.
ERROR:  42501: permission denied to alter role
DETAIL:  Only roles with the SUPERUSER attribute may alter roles with the SUPERUSER attribute.

Cause

The migration ran ALTER ROLE baci_wallet_dva_writer NOLOGIN NOSUPERUSER NOBYPASSRLS NOCREATEROLE NOCREATEDB NOREPLICATION;. The Management API login is not a superuser, and Postgres refuses any ALTER ROLE that merely names a superuser-class attribute (SUPERUSER, BYPASSRLS, REPLICATION) for such a login, even when nothing would change. The repo already learned this once: 20261104140100_piggyvest_webhook_intake_role.sql documents the same 42501 and only converges NOLOGIN.

What this PR changes

1. Migration fix. The ALTER ROLE now only sets NOLOGIN CONNECTION LIMIT -1 PASSWORD NULL, the same shape as the already-applied piggyvest_webhook_intake_role and blog_media_sweep_worker migrations. CREATE ROLE is unchanged and still creates the role NOLOGIN NOSUPERUSER NOBYPASSRLS NOCREATEROLE NOCREATEDB NOREPLICATION.
2. Security intent kept. A new catalog guard raises 42501 if baci_wallet_dva_writer has any elevated attribute (login, superuser, bypassrls, createrole, createdb, replication). It reads pg_roles, which any login may do, so it does not need superuser. The function boundary and every grant are untouched.
3. Checksum drift. The registry hashes in apps/web/tools/db/replay-registry/20261122064203_wallet_dva_restricted_writer/{pending,expected-pending}-sources.txt are regenerated with the README's own shasum command (0466499232dd… → 4eddf4a87542…). No shared aggregator or ci.yml is edited.
4. Regression test. apps/web/tools/db/wallet-dva-restricted-writer-migration.test.ts fails if any ALTER ROLE in this migration names a superuser-class attribute, and checks the NOLOGIN convergence, the CREATE ROLE attributes and the guard.

Why an existing migration is edited in place

Migrations are append-only so that a migration already recorded in production never changes underneath it. This one was never applied: the job log shows → applying and then an abort with "aborting before recording the migration", and the Management API runs a multi-statement query as one implicit transaction, so nothing partial was committed either. A new follow-up migration cannot fix this, because this migration aborts the job before any later migration runs. The owner's brief for this task pre-authorizes the in-place correction. CodeRabbit's "move this to a new migration" finding was evaluated and skipped for these reasons.

Verification

  • Scratch PostgreSQL 18, running as a non-superuser CREATEROLE login (like the deploy login): the old statements fail with permission denied to alter role; the new statements succeed, pg_roles shows baci_wallet_dva_writer with login/superuser/bypassrls/createrole/createdb/replication all false, a re-run is idempotent, and the guard rejects a pre-existing role with BYPASSRLS.

  • Local vitest, only the touched files, all green (9 files, 68 tests): the new regression test, replay-registry, replay-registry-baseline, materialize-supabase-history-replay{,-ordering,-relations}, verify-supabase-history-replay-{manifest,manifest-fixture-drift,gigl-pending-sources}.

  • Biome clean on the new test.
  • Not in this PR

  • Nothing is applied to the production database from here. The normal Deploy run applies the migration after merge.

  • The storefront edge inventory snapshot test also fails on main; that is covered by automation PR #4455 and left alone.

  • Per the repo's draft-first policy this stays a draft until Codex and Muse are clean on the current head. A merge to main is a production release, so it waits for the owner's go-ahead.
  • 🤖 Generated with Claude Code

    Diff: 552 lines (+414 / -138) across 6 files Reviewer: github-actions[bot] Review duration: 6m
    All Vouch review confidence checks passed
    Residual risk 0.52 = Change Risk (0.71) × (1 − Review Confidence (0.27)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.71 · 552 lines diff across 6 files
    0.71
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 48% · Reviewer familiarity: 35%
    26%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.378
    Shallow Review Depth shallow_review_depth
    0.344
    Sensitive Paths sensitive_paths
    0.071
    Real PR Conversation Timeline
    1 comments
    "Review active on #4457"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 26.9% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 71.3% (HIGH) · Higher = larger blast radius
    71.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 26.9% · Lower = rushed or shallow review
    26.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 52.1% · Moderate risk
    52.1%