AI Review for Database Migrations: Locks, Compatibility and Rollbacks

Review a database migration for write locks, old app versions, backfill load, rollback, and proof before release.

Axiom Studio Axiom Studio November 30, 2026 8 min read

A migration can pass code review and still stop writes. The SQL may be valid, yet the release can fail when an old app version reads the new schema, a backfill floods the database, or the team has no safe way back. Review the migration as a release plan, not just a file diff.

Start with one migration change

Suppose an orders table needs a new external_ref field and an index for lookup. The app will run old and new versions during deployment.

An AI reviewer should ask what each version reads and writes, how long the database may lock, and what happens if the rollout stops halfway.

Before reading the SQL, write down the release order. Which app version ships first? When does the migration run? When do old instances stop?

A migration that works after the new app deploys may fail while both versions are live. That overlap is the core review case.

Five questions for the pull request

  • What lock can each statement take, and what traffic will wait?
  • Can old and new app versions both read and write during rollout?
  • How much work will the backfill add to the primary and replicas?
  • Which steps run inside a transaction, and which must run outside one?
  • What stops the rollout, and what evidence will show it is safe to resume?

In PostgreSQL, a normal CREATE INDEX can block writes while the index builds. CREATE INDEX CONCURRENTLY allows writes to continue, but it takes more work and cannot run inside a transaction block.

Check the migration tool’s transaction setting before using it. The PostgreSQL CREATE INDEX guide explains these limits.

Review the SQL and the release path

Here is a small review diff. It shows a safer index command for a busy table, not a measured result. Run this statement outside a transaction. Check your PostgreSQL version and migration tool before release.

diff
// migration.sql — PostgreSQL
- CREATE INDEX orders_external_ref_idx ON orders (external_ref);
+ CREATE INDEX CONCURRENTLY orders_external_ref_idx ON orders (external_ref);

The reviewer must still inspect the surrounding ALTER TABLE. Lock behavior depends on the exact subcommand. A short lock can become a long outage when it waits behind another transaction.

Ask for a lock timeout, a release window, and a way to see blocked sessions. Do not claim that the word CONCURRENTLY makes the whole migration safe.

For example, adding a nullable column is often the first safe step, but the exact ALTER TABLE command still needs review.

PostgreSQL uses an ACCESS EXCLUSIVE lock for many ALTER TABLE forms unless the command says otherwise. The team should check the lock mode for the actual statement, not apply a blanket rule to all schema changes.

A reviewer should also look for a long transaction in the deploy script. If a migration framework wraps the index build in one transaction, the concurrent command will fail.

If a backfill updates millions of rows in one transaction, it can hold resources and make recovery harder. Split schema work, app rollout, and data updates into steps that the team can observe and stop.

Keep both app versions working

Use an expand, migrate, contract flow. First, add a nullable field without removing the old path. Next, deploy code that can read the old and new shapes.

Write new values only when every running version can handle them. Then backfill existing rows in small batches. Add a constraint or remove the old field only after the fleet has moved on.

For the orders example, a reviewer should ask: What does the old app do when external_ref is empty? Can the new app handle rows not yet backfilled?

Does a job update rows in batches, with a pause or stop switch? What will the team watch for replica lag, write latency, errors, and failed jobs? Those questions catch release risk that a syntax check cannot.

Use case: a new lookup field

The new external_ref may start empty on old rows. A new app that assumes it is always present can fail before backfill finishes.

Keep the field optional in code, add a clear fallback, and only make it required after the data and every app instance are ready. Reviewers should test a row with no value, a row with a new value, and a row written by the old app.

Use case: a large backfill

A backfill that looks simple in code can compete with user traffic. Set a bounded batch size and pause between batches. Watch write latency, replica lag, and errors.

If those move beyond the team’s chosen limit, pause the job. Do not present a batch size as safe until the team has checked it on its own data and load.

A database migration path moves through review checkpoints toward a safe release.

A staged migration gives old and new app versions time to share one database before the old path is removed.

Plan rollback before the first step

Rollback is not always “run the down migration.” Dropping a column can destroy data. Reversing a backfill can be hard when new writes continue.

Write a stop point for each stage: pause the backfill, turn off the new read path, or return traffic to the old app while leaving the additive column in place. Name the person who may stop the rollout.

Treat a failed index build as its own case. PostgreSQL can leave an invalid index after a failed concurrent build. The release plan should say how to detect that state and clean it up.

Test the stop and recovery steps in a safe environment; record what happened rather than assuming the steps will work.

Think about the order of reversal as well. Turning off the new app path may be fast, while undoing new data may not be. Keep the old data and code path until the team has passed the observation window.

In the pull request, label each step as reversible, stoppable, or hard to reverse. That tells the reviewer where human approval matters most.

Stage Main risk Proof to check
Schema Lock waits Exact SQL and transaction setting
App overlap Old or new code fails Both versions tested with new schema
Backfill Write load or replica lag Batch limit, pause switch, live signals
Contract No safe return path Observation window and human approval

Give the reviewer proof to check

Attach the SQL diff, table size, expected traffic, migration-tool settings, and the app deploy order. Add test results for both app versions against the expanded schema.

Show the backfill batch size and its stop switch. During rollout, watch lock waits, write latency, replica lag, error rate, and backfill progress. Set a clear threshold and owner for pausing work.

The review can be split between tools and people. An AI reviewer can spot a blocking index statement, a missing rollback note, or code that assumes the new field is never null.

The database owner should confirm lock risk and traffic. The app owner should confirm version overlap. The release owner should confirm stop rules and on-call coverage. A passing automated review does not replace those decisions.

Vera AI code review can flag risky changes on a pull request, but a human still needs to judge the live database plan. The guide to AI code review on GitHub and GitLab shows how review fits the merge path.

The quality gates guide explains why tests and checks should run before merge. Use those controls with a database owner’s sign-off for high-risk migrations.

A staged migration keeps old and new application versions compatible while data moves in bounded batches.

Watch lock waits, write latency, replica lag, and backfill pace during each stage. Pause when a chosen limit is crossed.

A short release checklist

  1. Confirm the exact PostgreSQL lock behavior and transaction limits for each statement.
  2. Prove old and new app versions work during the overlap.
  3. Run the backfill in bounded batches and watch load.
  4. Name stop points, rollback actions, and the person who can call them.
  5. Release in stages and keep evidence from the real run.

A good migration review ends with an order of operations and a way to stop safely. Bring that plan to the pull request before the SQL reaches production.

Use VibeFlow to keep the migration review, evidence, and release decisions visible alongside the rest of the software delivery plan. Request a demo to see how migration reviews, approvals and release evidence fit into one governed workflow.

Frequently asked questions

What should an AI reviewer check in a database migration?

Check the lock each statement can take, whether old and new app versions work during rollout, the load from a backfill, transaction boundaries, and the stop and recovery evidence for each stage.

Why can a valid migration still stop writes?

A valid SQL statement can wait on a lock or block traffic while it runs. The exact command, surrounding transaction, table activity, and release window determine the operational risk.

How should teams keep old and new app versions compatible?

Use an expand, migrate, contract flow: add an optional field, deploy code that handles both shapes, backfill in bounded batches, and remove the old path only after the fleet has moved on.

What makes a database migration rollback plan safe?

Name a stop point for each stage, say who can pause the rollout, keep a workable old path, and test recovery in a safe environment. Dropping a column or reversing new writes may not be reversible.

What evidence should accompany a migration pull request?

Attach the SQL diff, table size, expected traffic, migration-tool settings, deploy order, both-version tests, batch limits, stop switch, live signals, and the owner for pausing work.

Axiom Studio

Written by

Axiom Studio

Turn AI governance insight into evidence

Get weekly governance insights for engineering leaders, then put them to work with VibeFlow.