Repository navigation
Refuse to build against a database that is behind the schema - #256
Conversation
Three outages tonight had one shape: a pull request adds a column, ships, and the database it runs against has never heard of it. The docs tree, then permanent workspace deletion, which took out every page, because resolving a user's workspaces selects organization.deletion_requested_at. db:check-drift already reported this, but nothing ran it against the database that mattered. The CI job added earlier proves the committed migrations are complete; it never looks at production. The Vercel build now runs it first. A build whose database cannot answer what the code asks for fails, loudly, instead of deploying and answering 500 on every page. It fails only when it can prove drift. No DATABASE_URL, or a database it cannot reach, is reported and allowed through, because a transient network fault should not block a deploy, and being unable to check is not the same as knowing something is wrong. Adds packages/db/catchup/workspace-deletion-catchup.sql for the two columns that are missing right now, verified against a database rebuilt to match production.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThe PR adds a rerunnable database catch-up migration, introduces guarded drift-check behavior, tests the guard paths, and runs the guard before the web production build. ChangesDatabase deployment guard
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant WebBuild
participant CheckDrift
participant Database
WebBuild->>CheckDrift: run with --guard-deploy
CheckDrift->>Database: inspect live schema
Database-->>CheckDrift: return schema state or connection error
CheckDrift-->>WebBuild: allow build or refuse on drift
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/web/package.json`:
- Line 8: Update the build script so the root .env file is loaded before running
packages/db/src/check-drift.ts, ensuring the drift guard receives DATABASE_URL
and other configuration. Preserve the existing --guard-deploy behavior and Next
build command while applying the same environment source to both steps.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 7b2cb212-f823-4635-86e2-df92addd5da9
📒 Files selected for processing (4)
apps/web/package.jsonpackages/db/catchup/workspace-deletion-catchup.sqlpackages/db/src/check-drift.tspackages/db/tests/check-drift-guard.test.ts
The guard ran without the env file the build itself loads, so a local build whose DATABASE_URL lives only in the repository root env passed the check by finding no database, then built against that very database unchecked. On Vercel the platform supplies the variable and the guard saw it, which is exactly the kind of gap that only bites the person running it by hand. Both halves read ../../.env now. Verified against a database missing almost everything: the guard exits 1 and names what is missing, where before it exited 0 and said there was nothing to check.
Nothing outside the script reads it, and the build script names the flag as a literal, so exporting it added surface without adding a contract.
Why
Three outages tonight, one shape. A pull request adds a column, ships, and the database it runs against has never heard of it.
doc.sort_order→/docsand/api/syncdownorganization.deletion_requested_at→ every page down, because resolving a user's workspaces selects itdb:check-driftreported both. Nothing ran it against the database that mattered. The CI job added in #250 proves the committed migrations are complete; it never looks at the database a deploy will actually serve.So the loop still depended on someone remembering, and it failed twice in one evening.
What changed
The Vercel build runs the check first:
A build whose database cannot answer what the code asks for now fails, loudly, instead of deploying and returning 500 on every page.
DATABASE_URLis configured for both Production and Preview, so both are covered.It fails only when it can prove drift
This matters, or the guard becomes something people route around:
DATABASE_URLA transient network fault should not block a deploy, and being unable to check is not the same as knowing something is wrong. Without the flag the script keeps its old behaviour and exits 2 on a missing
DATABASE_URL, sodb:check-driftrun by hand still tells you when you have misconfigured it.Verified all four, then covered the three that are testable without a database in
tests/check-drift-guard.test.ts. Those spawn the script in a temporary directory, because bun auto-loads.envfrom the working directory and a test run from the repo root silently picks up a realDATABASE_URL— which is exactly how my first version of these tests fooled me.Also here
packages/db/catchup/workspace-deletion-catchup.sqlfor the two columns #246 shipped without:organization.deletion_requested_atandattachment.upload_expires_at. Both nullable timestamps, no indexes.Verified by rebuilding a database to match production's exact drift, applying it twice, and running the query from the production stack trace.
Already applied to production, which is back up and reports no drift.
Verification
packages/db: 163 passGreptile Summary
The PR prevents web builds from proceeding when the configured database is provably behind the declared schema.
Confidence Score: 5/5
The PR appears safe to merge.
No blocking failure remains.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Web build starts] --> B[Load repository .env] B --> C[Run schema drift guard] C -->|Database is behind| D[Fail build and report missing schema] C -->|Schema matches| E[Run Next.js build] C -->|Missing or unreachable database| F[Report schema unchecked] F --> EReviews (3): Last reviewed commit: "chore(db): keep the guard flag to itself" | Re-trigger Greptile