Skip to content
Technology, explained from the insideAI · Software · Digital payments
TayoTechTalk.

AI Software Development

AI-Generated Database Migrations: Review Before Deployment

By Temitayo Solomon Gbadebo · November 9, 2026
A staged database migration keeps old data available while reviewers expand the structure, prepare writers, backfill and check, switch readers and contract.

An AI coding assistant can turn a requested database change into a migration file in seconds. The difficult part is deciding whether that file can run while the application is serving people, preserving their data and supporting a recovery if something goes wrong.

A migration is a controlled change to a database’s structure or stored data. It might add a column, change a constraint or move values into a new format. A successful test on an empty development database answers only a small part of the review.

Our guide to testing AI-generated code explains how to check behaviour independently. Database migrations add another responsibility: reviewing what happens to records that already exist and to application versions running during the transition.

Start with the meaning of the change

Imagine a customer dashboard with a database column called name. The team wants to rename it display_name so its purpose is clearer. In this example, both columns mean exactly the same thing: the name a customer chooses to show in the dashboard.

That last sentence matters. If the new field meant a verified legal name, copying the existing values would not establish that they were verified. If the new field were required but older records were incomplete, inserting a convenient default could hide the missing information.

Write down the intended meaning before reviewing the generated SQL. For our illustrative rename, the requirements are simple: preserve every existing value, keep profile edits working and avoid breaking an older application instance during deployment. These are example requirements, not a claim about a real system or a tested migration.

Give the assistant the database engine and version, the migration framework, a sanitised schema and representative invented records. Ask it to identify assumptions and proposed destructive operations. Keep production credentials and customer records out of prompts unless their use is explicitly approved under the organisation’s data policy.

Review the application transition, not only the final schema

A direct rename may leave the database in the desired final shape. It can still break code that asks for name. During a rolling deployment, some application instances may run the old release while others run the new one. Background workers, scheduled jobs, reports and external integrations can also depend on the old column.

One approach is expand and contract: add the new structure, move use of the data across, then remove the old structure after its consumers have moved. Prisma’s migration guide describes this pattern. The particular commands depend on the installed tool version; the useful review principle is separating the transition from the cleanup.

For our rename, an illustrative sequence is:

  1. Expand: add display_name while keeping name. The old application continues using the old column.
  2. Prepare writers: deploy a compatibility release that still reads name but writes both columns together. Confirm that every relevant writer has moved to this behaviour.
  3. Backfill and check: copy and reconcile existing values using name as the authoritative value during this phase.
  4. Switch readers: after verification, deploy reads from display_name. Keep both values updated for the agreed application rollback period.
  5. Contract: remove dependence on name, then remove the column in a separately reviewed change.

This is a review outline, not a universal production recipe. A small application with an agreed maintenance window may use a simpler approach. A busy system with many writers may need database-level synchronisation or another strategy. The team needs evidence that its chosen sequence works for its actual deployment.

Challenge the backfill with a changing record

A backfill populates the new field for existing rows. The easy case is a record that never changes. A more revealing case is a customer editing their profile during the migration.

Suppose both columns initially contain “Kemi.” An older application instance then changes only name to “Kemi A.” The new column still contains “Kemi.” A backfill that copies only into empty fields will miss this mismatch because display_name is already populated.

That is why the example sequence waits for compatible writers before final reconciliation. The review must identify which value is authoritative at each stage and how conflicting values will be repaired.

Now test a second race: a backfill reads “Kemi,” a customer saves “Kemi A.,” and the backfill later writes its stale copy. The migration must use an appropriate concurrency strategy, such as row locking or a conditional update, so it cannot overwrite a newer edit with an old value. Review and test the specific implementation rather than treating “runs in a transaction” as a complete explanation.

Ask the assistant to walk through these events in order, with the value of each column after every step. A concrete timeline often exposes a mistake that a fluent description of the migration misses.

Check locking and load separately

A change that preserves values can still interrupt the service. Database operations acquire locks to coordinate concurrent access, and some changes require scanning or rewriting substantial amounts of data.

For example, the PostgreSQL 17 ALTER TABLE reference documents the lock requirements of individual operations. It states that an ACCESS EXCLUSIVE lock is the default unless a particular form specifies otherwise. A claim that an operation avoids rewriting the table therefore does not establish that it avoids locking.

Have the reviewer check the deployed database version, the exact command and its transaction boundaries. How long might it wait for a lock? What happens to application requests while it waits or runs? What timeout or stop condition will the operator use? Follow the database’s documented behaviour rather than assuming a command behaves identically across engines.

For a large backfill, consider bounded batches with observable progress rather than one unbounded update. GitLab’s database migration guidance provides a practical example of small, retry-safe background jobs and monitoring database health. Its framework is specific to GitLab, but the questions are useful elsewhere: can work pause, resume and retry without damaging data?

Choose batch sizes from measurements in a representative environment. There is no universal “safe” number of rows. Watch request latency, database load, lock waits and replication lag where applicable. Set thresholds before the change starts, with a named person responsible for stopping it.

Verify data, compatibility and interrupted execution

A migration test should begin with meaningful existing data. For the dashboard example, include empty values if allowed, long names, accented characters and records created before the new field existed. Use synthetic or appropriately de-identified fixtures in an approved test environment.

Keep the checks tied to the requirements:

  • Preservation: every existing customer retains the expected name and record identifier.
  • Consistency: while both columns represent the same value, check for mismatches as well as missing values. Row counts alone cannot prove correctness.
  • Compatibility: exercise the old and compatibility application versions against the expanded schema, then test the reader switch.
  • Concurrent changes: edit a profile while the backfill processes it and confirm that the newest accepted edit survives.
  • Recovery from interruption: stop a test backfill partway through, restart it and retry a completed batch. Check for omissions and unintended changes.
  • Cleanup: verify that remaining jobs, reports and application paths no longer depend on the old column before removing it.

Test against the actual database engine and relevant version, not only an in-memory substitute. Record the migration commands, application versions, dataset characteristics and observed results. Make clear which checks actually ran and which remain proposals. Passing a small test environment does not establish production timing.

Separate application rollback from data recovery

“We can roll back” needs a precise meaning. Reverting application code does not automatically restore deleted data. A generated downward migration that recreates a dropped column may restore its structure without restoring its contents.

In our example, keeping both columns current allows an older compatible application release to keep reading the old field during the rollback period. Once the old column is removed, that option changes. Treat the cleanup as a separate decision with its own evidence and approval.

For destructive transformations, document how the original values could be recovered and rehearse the procedure. PostgreSQL’s point-in-time recovery documentation explains recovery using a base backup and the required archived write-ahead logs. Simply having a backup file is not evidence that the complete recovery process works.

Also decide what happens to legitimate activity after the chosen recovery point. Restoring an earlier database state can remove later customer changes. The recovery plan should explain how those changes will be identified and handled, how long restoration is expected to take and who decides to proceed.

Ask the assistant for a reviewable proposal

A useful request is: “Explain this migration for our stated database version. List each schema and data change, affected readers and writers, rollout order, locking concerns, backfill retry behaviour, verification queries and recovery options. Identify assumptions and destructive steps. Do not execute it.”

Use the answer to organise the review, then verify the important claims against official documentation and observed tests. Ask for the generated migration file itself, not only the model or schema change that produced it. A migration tool’s output is part of the change being approved.

The final review should make five things clear: what existing data means, how it stays correct during the transition, how service disruption will be limited, what evidence demonstrates success and what recovery remains possible. AI can help prepare that work. Approval should rest on the actual migration and a tested operational plan.