What the agent does
The agent checks out the pull request's branch and reads the migration machinery before the migration. In an Axum service like launchbadge/realworld-axum-sqlx, migrations are plain SQL files under migrations/, numbered 1_setup.sql, 2_user.sql, 3_follow.sql and 4_article.sql, and src/main.rs embeds them with sqlx::migrate!() and runs them against the pool at startup, so a migration that fails stops the binary from serving at all. migrations/README.md explains the rules: the version is any unique non-decreasing integer, sqlx migrate add defaults to a Unix timestamp, SQLx records each applied file's content hash in _sqlx_migrations, and an applied file must never be edited. 1_setup.sql creates the uuid-ossp extension for uuid_generate_v1mc(), a set_updated_at() trigger function with a trigger_updated_at(regclass) helper that every table is expected to call, and a case_insensitive ICU collation (und-u-ks-level2, non-deterministic) used by "user".username and email so unique enforces case-insensitive uniqueness, with a comment warning that LIKE and ILIKE do not work on that collation and a search needs a second index under ucs_basic.
The rest of the schema sets the conventions a new migration is reviewed against. Table names are singular and the primary key carries the table name (user_id, article_id) so joins read using (user_id). follow has a user_cannot_follow_self check constraint and a composite primary key with following_user_id first, chosen because the spec asks who a user follows and not who follows them. article stores tag_list text[] with a GIN index article_tags_gin, article_favorite has a composite key on (article_id, user_id), and article_comment keeps a bigserial key the comments explain should never be used for ordering, with an index on (article_id, created_at) for the lookup the handlers make. Every foreign key is on delete cascade, every table has created_at timestamptz not null default now(), and every table ends with select trigger_updated_at('...'). A new table that skips the trigger call, uses a plural name, adds a text identity column without the collation, or adds a not null column without a default to a populated table, is what the review is for.
The code matters because the queries are checked at compile time. Each handler under src/http writes its SQL inline with sqlx::query!, query_scalar! or query_as!, which SQLx verifies against the database at DATABASE_URL when cargo build runs; the repository has no .sqlx directory or sqlx-data.json, so there is no offline mode and a renamed column that a handler still selects fails the build rather than a request. src/http/error.rs maps database errors by constraint name through .on_constraint("user_username_key", ...) into the spec's 422 body, so a migration that renames a unique constraint turns a validation error into a 500 without changing a line of Rust. src/http/users.rs builds its UpdateUser from #[serde(default)] optional fields, src/http/articles/mod.rs and listing.rs read tag_list, and profiles.rs joins follow, so the review reads those files against the diff.
The procedure follows .github/workflows/rust.yml. The agent starts the postgres image in its sandbox with the workflow's POSTGRES_PASSWORD, sets DATABASE_URL to postgresql://postgres:password@localhost/realworld_axum_sqlx and an HMAC_KEY as .env.sample describes, installs sqlx-cli with the postgres feature, and runs sqlx db setup on the base branch to apply the existing migrations. It inserts a user, a follow, an article with tags, a favorite and a comment so the tables are populated, then applies the pull request's files with sqlx migrate run and keeps the output, because a not null without a default or a check constraint the seeded rows violate fails right there. It runs cargo build --verbose so every macro is rechecked, cargo test --verbose, and when the handlers changed, cargo run with the Realworld Postman collection the workflow checks out from abonander/realworld at its pinned ref, through run-api-tests.sh against APIURL=http://localhost:8080/api.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "Review the SQLx migrations added by the open pull request in resources. Read migrations/README.md, every file under migrations, src/main.rs, src/http/error.rs and the handlers under src/http that touch the tables the diff changes, plus .github/workflows/rust.yml and .env.sample. Start the postgres image in the sandbox with a fresh database only, never a production connection, set DATABASE_URL and HMAC_KEY as the workflow does, install sqlx-cli with the postgres feature, and run sqlx db setup on the base branch. Insert a user, a follow, an article with tags, a favorite and a comment, then check out the pull request branch and run sqlx migrate run, keeping the output. Run cargo build --verbose and cargo test --verbose; when a handler changed, also run the server and the Realworld Postman collection as the workflow does. Check that each new file has a unique non-decreasing version and that no applied file was edited, that new tables are singular with a table-named primary key, call trigger_updated_at, have created_at with a default, use the case_insensitive collation on identity text columns, and use on delete cascade deliberately; that no not null column is added without a default to a populated table; that every query! macro and every .on_constraint name still matches the schema; and that new lookups have an index. Post one review on the pull request with a comment on each offending line that names the rule and the fix, and a summary quoting the migrate, build and test output. Do not push commits and do not edit any migration.",
"resources": [
{
"url": "https://github.com/your-org/your-app/pull/42"
}
]
}- 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.
- 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.
- 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
The pull request receives one review with comments on the lines of the new migration files and, where the code lags the schema, on the handler that still names an old column or constraint. Each comment states the convention it breaks and the change that fixes it: the missing select trigger_updated_at(...), the plural table name, the identity column without collate "case_insensitive", the not null column with no default, the renamed constraint that .on_constraint no longer matches, the lookup with no index. The summary quotes the sqlx migrate run output on the seeded database, the cargo build result that rechecked every macro, and the cargo test summary.
The session read at GET /o/{org}/sessions/{id} names the pull request and the review, and the transcript at GET /o/{org}/sessions/{id}/messages keeps every command: the Postgres start, sqlx db setup, the seed inserts, the migration run and its errors if any, and the build. The run pushes nothing, so there are no changes to read; the review is the result.
Before merging, a reviewer reads the comments against the files, checks that a migration the agent could not apply is fixed by a new file rather than by editing the one in the pull request, and decides on the cases the conventions leave open, such as whether a new relation should cascade on delete or keep its rows for auditing, which 3_follow.sql discusses at length.
Run it on every pull request that touches migrations
Add an automation to the Project with this prompt and a github trigger on pull_request.opened and pull_request.synchronize, with branch_patterns set to main. A trigger filters on the base branch, labels and authors, not on paths, so the prompt tells the agent to end at once with a one-line result when the diff has no file under migrations/. The trigger adds the pull request event after the prompt and fills in nothing, so the agent reads the number from the event; pull requests from forks never fire it, and the automation's max_runs_per_hour, between 1 and 30, caps how many it reviews in an hour.
From your own server instead, a handler that receives GitHub's pull_request webhook can check the changed files with the GitHub API and send POST /o/{org}/sessions only when one is under migrations/, with the pull request URL in resources and a request_id that is a UUID v5 of the delivery id and head commit, so a redelivered webhook returns the run already started. Give the key a webhook_url and Rush POSTs run.completed when the review is posted.
The use case this job follows, with its automation and trigger: Review every pull request.
Why run it on Rush?
A SQLx migration cannot be reviewed by reading it, because the compile-time macros tie the Rust code to the live schema: the only way to know whether a pull request's migration breaks a handler is to apply it to a Postgres with rows in it and rebuild. That takes a database, sqlx-cli, the seed data and a full build, which is more than a reviewer does for every pull request. The agent does exactly that in its own sandbox, on a fresh database it throws away.
The review it posts carries the evidence inline: the migration output on populated tables, the build that rechecked every query!, the test summary, and a comment on each line with the rule it breaks. Several pull requests are reviewed at once, each with its own Postgres, and nothing is pushed, so the author keeps control of the branch and the fix is a new migration file in their own commit.
Frequently asked questions
Can it run the migration against our staging database instead?
No, and the prompt forbids a production or shared connection. The review applies the migration to a fresh Postgres in the sandbox, seeded with representative rows, so a failing migration costs nothing. A migration that passes there and fails on real data because of a value the seed did not contain is the reviewer's call, and the comments say what the seed covered.
Why does it need DATABASE_URL just to build?
Because every handler uses sqlx::query! and its relatives, which connect to DATABASE_URL at compile time to check each statement's columns and types, and this repository ships no offline query data. That is also why the build is the strongest check in the review: a column the migration renames fails cargo build in the handler that still selects it.
What about down migrations?
The project uses irreversible files, as migrations/README.md says .up and .down pairs are not needed here, so there is nothing to run backwards. The review instead checks that the pull request adds a new file rather than editing an applied one, since SQLx compares content hashes in _sqlx_migrations and refuses a changed file on the next start.
Will it edit the migration or push a fix?
No. It posts a review with a comment per line and a summary, and pushes no commits. A fix that edits a migration already applied somewhere would break the hash check, so the right fix is a further migration file, and that belongs to the pull request's author.