# Testing database migrations in CI

> Run migration checks on representative existing records and new writes. Inspect defaults and changed values before deploying the schema.

Source: https://cueapril.com/guides/test-database-migrations-in-ci
Updated: 2026-12-01
Index: https://cueapril.com/llms.txt

## What should a PR check prove before a schema backfill is allowed to run?

A migration check should read old data, apply the change, verify the new behaviour and record which recovery path was exercised. A fresh empty database covers only the easiest case.

A reminder preference moves from an implied default to an explicit field.

## Work through the decision

A fixture containing only new rows will miss the customers whose old rows have no value.

Steps and evidence for the reviewer

| Step | Evidence to keep |
| --- | --- |
| Seed historical shapes | Include absent, false and true values. |
| Apply the migration | Record counts and unchanged business invariants. |
| Verify recovery | Restore or roll forward using an isolated copy and compare outcomes. |

## What changes the decision

For a large change, test a representative batch and a partially completed backfill as separate states. Keep the migrated revision and dataset identifiers together.

## Primary documentation

- [PostgreSQL documentation on modifying tables](https://www.postgresql.org/docs/current/ddl-alter.html)

By Cue April. Updated 2026-12-01.

## Related

- [Testing guides](https://cueapril.com/guides): Learn how to select regression checks, verify generated tests and read failure evidence. Use examples that connect a code change to user behaviour.
- [Worked test reports](https://cueapril.com/reports/schema-default-migration): See how a local migration fixture affects existing rows and newly created records. Inspect the expected defaults and the regression a fresh database misses.
- [Pull request testing](https://cueapril.com/use-cases/pull-request-testing): See what a pull request test report should show before you merge. Follow a failing checkout check through the fix and inspect a real PR report.
