All jobs

Review Drizzle Migrations in Every Pull Request

Yes. The agent applies each new Drizzle migration to a database that already has rows, checks it against the schema file and comments on the SQL that would fail.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

A Drizzle pull request has two things that must agree, the TypeScript schema and the SQL that drizzle-kit generate wrote from it, and the test suite often checks neither against a real upgrade. The agent reads how the project is wired before it reads the diff. In a project like w3cj/hono-open-api-starter, drizzle.config.ts names ./src/db/schema.ts as the schema and ./src/db/migrations as the output, with dialect turso and casing: "snake_case". The config imports src/env.ts, which exits with an invalid-env message when no .env exists, so every drizzle-kit command needs cp .env.example .env first. And the one test file calls pnpm drizzle-kit push in beforeAll: the suite builds its database straight from the schema file and never executes a line of the SQL under src/db/migrations.

That gap is where the review earns its place. Take a pull request that adds priority: integer().notNull().$defaultFn(() => 0) to the tasks table. The default lives in application code, so the generated migration is a single ALTER TABLE statement that adds priority as integer NOT NULL with no DEFAULT. All twelve tests pass, because push creates the table fresh. drizzle-kit migrate on an empty database succeeds too. On a database with a single row in tasks it stops with SQLITE_ERROR: Cannot add a NOT NULL column with default value NULL. The agent finds this the only way it can be found: it applies the base branch's migrations to a scratch SQLite file, inserts rows into every table the pull request touches, then applies the pull request's migrations on top.

Around that it runs the consistency checks. drizzle-kit generate on the pull request's branch must answer that there are no schema changes; if it writes a new file, the committed migration and schema.ts disagree. Each new SQL file must have its entry in meta/_journal.json and its snapshot beside it, and no migration that exists on the base branch may be edited, since databases that already ran it will never run it again. drizzle-kit check is run and reported, though the agent does not lean on it alone: with a snapshot file deleted it still answers that everything is fine. Because generate compares snapshots and not SQL, a hand-edited migration passes it, so the agent also compares the table the migrations produce, read with PRAGMA table_info, with the one push produces from the schema.

The last pass is the code. The casing option is set in two places, drizzle.config.ts and the drizzle() call in src/db/index.ts, and a pull request that changes one makes queries ask for column names the migration never created. A column added to the table also flows into the zod schemas that createSelectSchema and createInsertSchema derive in schema.ts, and so into the request bodies and the OpenAPI document; the agent names each route whose contract the migration changes.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Review the Drizzle migrations in the open pull request in resources. Read drizzle.config.ts, the schema file it names, every file under the migrations directory including meta/_journal.json and the snapshots, the database client module, the env module, the tests and package.json first. Create .env from .env.example so drizzle-kit can load its config. Confirm that no migration present on the base branch was edited and that every new SQL file has a journal entry and a snapshot. Run drizzle-kit generate on the pull request's branch and report whether it finds schema changes; run drizzle-kit check and report it, without treating it as proof. Then test the upgrade with synthetic rows only: check out the base branch's migrations, apply them with drizzle-kit migrate to a scratch SQLite file by setting DATABASE_URL, insert at least one row into every table the pull request alters, then apply the pull request's migrations and record each statement that fails with its error. Compare PRAGMA table_info for each table after migrate with the same table created by drizzle-kit push from the schema, and list any difference. Check that the casing option matches between drizzle.config.ts and the drizzle() call, and list every route whose request or response schema changes because of a new or removed column. Run the project's typecheck and tests and report them. Post one review on the pull request: results first, then a comment on the exact line of each migration statement that failed or is destructive, with the error, a safe alternative and how to undo it. Change no file and push nothing.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app/pull/42"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

One review on the pull request. It opens with a results block: whether generate found changes, what check said, whether base-branch migrations were edited, the outcome of applying the new migrations to a database with rows, and the typecheck and test results. A migration that applied cleanly gets a single line saying so with the row counts it was tested against.

Findings follow as comments on the lines of the SQL file. For the NOT NULL column above, the comment quotes the SQLite error, explains that $defaultFn supplies its value in the application and not in the database, and gives the two usual ways out: a .default(0) so the generated SQL carries a DEFAULT, or a nullable column with a backfill and a later migration that tightens it. Drizzle writes no down migrations, so each destructive statement also gets the SQL that would restore what it removes.

A reviewer weighs the comments against how they deploy. Whether the production database is ever empty, how large the altered table is and whether a backfill belongs in the migration or in a script are things the team knows and the agent does not. The agent pushes nothing, so the fix stays with the author.

Run it on every pull request that changes the schema

An automation in the Project that holds the repository, with this prompt, read-only switched on and a github trigger on pull_request.opened and pull_request.synchronize, starts a review when a pull request opens and on each push to it. The trigger puts the event after the prompt and fills in nothing. A trigger has no path filter, so the automation's prompt begins by telling the run to end with a one-line note when the pull request touches neither the schema file nor the migrations directory. With read-only on, the run can read the repository and comment and cannot push.

A team that wants only schema changes reviewed starts the run from its own GitHub webhook handler: when a pull request's changed files include the schema or a migration, the handler sends this body to POST /o/{org}/sessions with the pull request's URL in resources and a request_id that is a UUID v5 of the head SHA, so a redelivered webhook returns the run already started.

The use case this job follows, with its automation and trigger: Review every pull request.

Why run it on Rush?

The decisive step is applying SQL to a database that has data, and nobody wants a reviewer doing that against anything shared. The run does it in its own sandbox against a SQLite file that exists only there, filled with rows the agent made up. Each drizzle-kit command and its output is in the transcript at GET /o/{org}/sessions/{id}/messages, so the error quoted in the review can be traced to the command that produced it.

It is also a review that has to happen on every push, including the ones on a Friday afternoon. A migration is the one kind of change a rollback of the application does not undo, and the check that catches a bad one takes a few minutes of mechanical setup that people skip when the tests are green.

Frequently asked questions

We use Postgres, not SQLite. Does the same review work?

The method is the same and the database differs. The agent installs PostgreSQL in its sandbox, applies the base migrations, inserts rows and applies the new ones. It also reports which statements take locks that block writes, a question SQLite does not raise. Say which dialect and version you run in the prompt.

Does it need our production database URL?

No, and you should not give it one. The review uses a scratch database inside the sandbox with synthetic rows. The prompt sets DATABASE_URL to a local file for every command so the values in your .env.example are never used to reach anything.

We deploy with drizzle-kit push and keep no migration files. Is there anything to review?

Yes, the same upgrade. The agent creates a database from the base branch's schema with push, inserts rows, then runs push from the pull request's schema and records what happens to the tables and the rows in them. Without migration files there is no SQL to comment on, so findings go on the lines of the schema file.

Why not trust drizzle-kit check?

It checks that the migration history is consistent, which is worth knowing and is in the report. It does not run the SQL against data. The failure in the example on this page passes check, passes generate and passes the tests.

More Drizzle jobs

The same job on other stacks

Keep reading