Skip to content

Make the committed migrations produce the schema they claim - #250

Merged
imshashank merged 2 commits into
mainfrom
fix/migrations-match-the-schema
Aug 8, 2026
Merged

imshashank merged 2 commits into
mainfrom
fix/migrations-match-the-schema

Conversation

@imshashank

@imshashank imshashank commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

The problem

Someone installing Orbit and following the migration path got a broken database.

bun run db:migrate on a fresh database, before this change:

localhost/orbit_fresh_migrate is behind packages/db/src/schema:
  missing table   doc_access
  missing table   doc_access_request
  missing table   doc_comment
  missing table   github_installation
  missing table   github_repository
  missing table   github_repository_link
  missing table   integration_oauth_state
  missing table   mcp_grant
  missing table   oauth_access_token
  missing table   oauth_application
  missing table   oauth_consent
  missing table   view_preference
  missing column  doc.search_vector
  missing column  doc.slug
  missing column  doc.sort_order
  missing column  doc_collection.position
  ...

Twelve tables and nine columns. mcp_grant, oauth_application and oauth_access_token are the MCP OAuth tables, so on that database the MCP server could not authenticate anyone at all.

The baseline was generated before the doc tree, GitHub connect, saved view and MCP OAuth work and was never regenerated. db:push builds the right thing because it reads the schema directly, so the two documented paths produced two different databases and only one of them worked.

This is the same class of failure that took /docs and /api/sync down: schema that exists in code but not in a database. That one was a database nobody had applied the change to. This one ships in the repository.

What changed

The baseline is regenerated from packages/db/src/schema. A fresh db:migrate now answers:

localhost/orbit_fresh_migrate2 has every table and column the schema declares.

Including the pieces that are easy to lose: doc.search_vector as GENERATED ALWAYS AS (...) STORED with its GIN index, doc.sort_order, doc_collection.position, and all four of the MCP and doc access tables.

Replacing the baseline strands nobody: no database tracks the old journal. Checked production and a dev database, and neither has a __drizzle_migrations table, because production is brought forward with the scripts in packages/db/catchup and development uses db:push.

So it cannot rot again

A CI job builds a database the way someone installing this would, with db:migrate and nothing else, then runs db:check-drift against it. If a schema change lands without regenerating the baseline, that job fails.

This is the check that would have caught the current state, and it is cheap: one Postgres service and two commands.

Verification

  • fresh database + db:migrate + db:check-drift: clean, confirmed before and after so the failure is reproducible
  • fresh database + db:push + db:check-drift: clean, unchanged by this PR
  • packages/db tests: 150 pass
  • lint, comment policy, typecheck: clean

Not in this PR

The four standup* tables are still in production and no longer in the schema, so db:push against production would drop them and the 31 rows they hold. db:check-drift reports them on every run. Removing them is a data decision, not a schema one.

Greptile Summary

The PR regenerates the baseline migration from the current schema and adds CI validation for fresh migration-based installations.

  • Adds missing tables, columns, constraints, indexes, and schema metadata to the baseline.
  • Installs pg_trgm through the database migration command before running Drizzle migrations.
  • Creates a fresh PostgreSQL database in CI, migrates it, and checks it for schema drift.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains; the migration command now installs pg_trgm before applying the baseline, and the CI job exercises that same fresh-database path.

Important Files Changed

Filename Overview
packages/db/drizzle/0000_shocking_baron_zemo.sql Regenerates the baseline with the current schema; its trigram indexes are now preceded by extension installation in the migration command.
packages/db/package.json Updates the migrate command to install required PostgreSQL extensions before invoking Drizzle.
.github/workflows/ci.yml Adds a fresh-database migration and drift-check job that exercises the corrected migration path.
packages/db/drizzle/meta/0000_snapshot.json Updates the Drizzle snapshot to represent the regenerated baseline schema.
packages/db/drizzle/meta/_journal.json Replaces the journal entry with the regenerated baseline migration identifier.

Sequence Diagram

sequenceDiagram
    participant CI
    participant Installer as ensure-extensions.ts
    participant DB as Fresh PostgreSQL
    participant Drizzle
    participant Drift as check-drift.ts
    CI->>DB: Create orbit_from_migrations
    CI->>Installer: "Run @orbit/db migrate"
    Installer->>DB: CREATE EXTENSION IF NOT EXISTS pg_trgm
    Installer->>Drizzle: Continue after extension succeeds
    Drizzle->>DB: Apply regenerated baseline
    CI->>Drift: Run db:check-drift
    Drift->>DB: Read migrated tables and columns
    Drift-->>CI: Confirm migration matches schema
Loading

Reviews (2): Last reviewed commit: "fix(db): let migrate install the extensi..." | Re-trigger Greptile

Someone installing Orbit and running db:migrate got a database missing
twelve tables and nine columns, including mcp_grant, oauth_application
and oauth_access_token, so the MCP server could not authenticate anyone.
The baseline migration was generated before the doc tree, GitHub connect,
saved view and MCP OAuth work and was never regenerated, while db:push
built the right thing from the schema. Two documented paths, two
different databases.

Regenerate the baseline from the schema. A fresh db:migrate now answers
db:check-drift with everything the schema declares, including the
generated search_vector and the doc tree columns whose absence took
production down.

Nothing tracked the old journal, in production or in a dev database, so
replacing the baseline strands no one.

CI now builds a database the way someone installing this would, with
db:migrate alone, and fails when it does not match the schema. That is
the check that would have caught this.
@imshashank
imshashank requested a review from pulkitxm as a code owner August 8, 2026 18:11
@vercel

vercel Bot commented Aug 8, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
orbit Ready Ready Preview Aug 8, 2026 7:09pm

Request Review

@github-actions github-actions Bot added area: database Schema, migrations, queries, seed ci Workflows, tooling and repo automation labels Aug 8, 2026
@coderabbitai

coderabbitai Bot commented Aug 8, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@imshashank, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 1 minute

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 21aff46d-f807-4df0-b307-e65f6d9a1d4c

📥 Commits

Reviewing files that changed from the base of the PR and between f7db206 and b4bc745.

📒 Files selected for processing (5)
  • .github/workflows/ci.yml
  • packages/db/drizzle/0000_shocking_baron_zemo.sql
  • packages/db/drizzle/meta/0000_snapshot.json
  • packages/db/drizzle/meta/_journal.json
  • packages/db/package.json

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

The baseline creates gin_trgm_ops indexes, so drizzle-kit migrate alone
aborted on a database without pg_trgm and left nothing behind: zero
tables. push never hit this because it runs ensure-extensions first, and
migrate did not.

Give migrate the same step push has.

The CI job added in this PR was creating the extension itself before
calling migrate, so it proved migrations work on a database someone had
already prepared, not on the fresh one the job claims to build. It now
creates an empty database and runs migrate alone, which is what someone
installing this actually does. Verified against a database carrying only
plpgsql: reproduced the abort, then applied clean with no drift.
@github-actions github-actions Bot added the dependencies Dependency updates label Aug 8, 2026
@imshashank

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@imshashank
imshashank merged commit 373ca37 into main Aug 8, 2026
13 checks passed
@imshashank
imshashank deleted the fix/migrations-match-the-schema branch August 8, 2026 19:16

This branch was successfully deployed

1 active deployment
Preview — b4bc745b Deployed Aug 8, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: database Schema, migrations, queries, seed ci Workflows, tooling and repo automation dependencies Dependency updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant