A safe database migration is more than a SQL statement: it is a deployment plan that protects application compatibility, controls locking and load, verifies data, and defines what to do if the change must stop. This database migration checklist provides a reusable workflow for planning schema changes, testing rollbacks, handling backfills, and reducing the risk of production downtime.
Overview
Database migrations change the structure or contents of a database while an application is being developed or operated. Common examples include adding a column, creating an index, changing a data type, splitting a table, or moving data into a new representation. The safest approach treats each migration as part of an application release rather than as an isolated database task.
Start by classifying the change. A low-risk migration might add a nullable column without changing existing queries. A higher-risk migration might rewrite a large table, acquire a long-running lock, convert a data type, or remove a column still used by an older application instance. Risk depends on table size, write volume, database engine, indexes, transaction behavior, deployment strategy, and the exact version of the database.
For changes that must coexist with old and new application versions, use an expand-and-contract process:
- Expand: add the new column, table, index, or compatible structure without removing the old path.
- Migrate: deploy application code that can read or write both representations, then backfill or copy data in controlled batches.
- Switch: direct normal traffic to the new representation and monitor results.
- Contract: remove the old column or table only after code, jobs, dashboards, and operational scripts no longer depend on it.
This pattern makes rollback more realistic. A rollback usually means reverting application code and stopping a migration step, not magically undoing every schema change. Destructive operations and one-way data transformations require a separate recovery plan.
Before formatting or reviewing a complex statement, a SQL formatter can make differences easier to inspect. The SQL Formatter Guide is useful when comparing dialect-specific syntax, but formatted SQL should still be tested against the actual database engine.
Checklist by scenario
For every migration
- Write down the purpose, affected objects, expected duration, and success criteria.
- Identify every application version, worker, scheduled job, report, and integration that reads or writes the affected data.
- Confirm that the migration is committed to version control and can be run consistently in a disposable or staging environment.
- Review table size, indexes, foreign keys, recent query performance, and expected write volume.
- Confirm backup availability and understand how restoration would affect the recovery-time objective.
- Define an owner, a deployment window, an abort threshold, and a communication path for incidents.
- Record the forward migration, the safe stop point, and the recovery procedure separately.
Adding a column or table
Prefer additive changes first. A nullable column or a new table is often easier to deploy alongside existing application code than an immediate constraint or required value. If the column will eventually be required, introduce it in stages:
- Add the column in a backward-compatible form.
- Deploy code that writes the value for new records.
- Backfill older records in small, observable batches.
- Check for missing or invalid values.
- Add the final constraint only after application behavior and data quality are verified.
ALTER TABLE accounts ADD COLUMN display_name VARCHAR(200);The exact type and syntax should match the database dialect. Avoid assuming that adding a default, adding a constraint, or changing nullability has the same lock and rewrite behavior on every engine.
Adding an index
Indexes can improve reads but may consume resources while they are built and may add write overhead afterward. Check whether the engine supports an online or concurrent index operation, what transaction restrictions apply, and how the operation behaves if interrupted. Test the execution plan before and after the index, and monitor lock waits, replication delay, CPU, storage, and query latency during the build.
CREATE INDEX idx_orders_customer_id ON orders (customer_id);Do not treat an index command as harmless solely because it does not change row values. On a busy table, the build itself can be the operational risk.
Backfilling data
Backfills should normally be resumable and bounded. Process records by a stable key or time range, commit small batches, and record progress. Avoid one enormous transaction unless the database, table size, and operational testing clearly support it.
UPDATE customer_profiles
SET normalized_email = LOWER(email)
WHERE id > :last_id
AND id <= :next_id
AND normalized_email IS NULL;Use a representative test dataset to estimate work, but treat the estimate as directional. Production distribution, concurrent writes, triggers, replication, and cache behavior can change the result. If the application can update the same rows during the backfill, define which process wins and how conflicting values are handled.
Changing or removing a column
Do not rename or drop a column until all application versions and dependent systems have stopped using it. A safer rename often consists of adding a replacement, dual-writing temporarily, copying and validating values, switching reads, and removing the original later.
For a type change, first test boundary values, invalid values, indexes, sorting, joins, serialization, and ORM behavior. A rollback may be impossible if the conversion loses precision or truncates information, so preserve the original data until validation is complete.
Engine and hosting comparison
| Environment | Planning focus | Rollback consideration |
|---|---|---|
| PostgreSQL | Check lock modes, transaction behavior, table rewrites, index options, and version-specific DDL behavior. | Transactional DDL may help for some operations, but an application rollback still does not reverse committed data changes automatically. |
| MySQL | Verify storage engine, online DDL support, metadata locks, algorithm choices, and version-specific limitations. | Some operations may rebuild or copy data; prepare a forward-compatible recovery path rather than relying on a quick reverse statement. |
| SQLite | Review supported ALTER operations, table-copy patterns, file locking, and the effect of concurrent readers or writers. | Keep a tested database-file backup and validate restoration. A migration that is inexpensive elsewhere may require rebuilding a table. |
| Managed database | Check provider-specific maintenance controls, replicas, backups, connection limits, failover behavior, and restrictions on administrative operations. | Understand whether restoring or promoting a backup changes endpoints, data freshness, permissions, or application configuration. |
This table is a planning guide, not a substitute for the documentation for your database version and hosting platform. Migration-framework commands also vary by tool and release; verify the exact command, dry-run option, transaction mode, and status-reporting behavior before production use.
What to double-check
Locks and transaction behavior
Ask what locks the operation requires, how long they may be held, whether blocked writes accumulate, and what happens when a lock timeout is reached. A migration can be syntactically correct yet operationally unsafe if it competes with high-volume traffic. Test with concurrent reads and writes, not just an idle database.
Compatibility during deployment
Rolling deployments may run old and new application versions at the same time. Confirm that both versions tolerate the intermediate schema. The same applies to background workers, command-line scripts, analytics pipelines, and external consumers. API contracts and database contracts should be reviewed together; the OpenAPI workflow guide can help when a schema change also affects an API response or request.
Observability
Define what you will watch before starting:
- Migration duration, progress, and error rate.
- Lock waits, deadlocks, active connections, and transaction age.
- Read and write latency, application errors, timeouts, and queue depth.
- Replication or backup health where applicable.
- Counts, null rates, checksums, or other validation measures for changed data.
Capture a baseline before deployment. Without a baseline, it is harder to distinguish migration impact from normal traffic variation.
Rollback versus roll-forward
Choose the recovery method before deployment. A rollback may be appropriate when the migration has not changed data and the reverse operation is known to be safe. A roll-forward is often safer after a backfill or transformation: stop the faulty process, preserve evidence, deploy a corrective migration, and keep the schema compatible until the data is repaired.
Document the point at which reversal is no longer safe. For example, after a destructive drop or lossy conversion, restoring a backup may be the only complete recovery option. Test the restoration procedure separately; having a backup is not the same as proving that it can be restored within an acceptable window.
Common mistakes
- Combining unrelated changes: Separate a large index build, data cleanup, and column removal so each can be observed and stopped independently.
- Using a single massive backfill: Large transactions can increase lock duration, log volume, replication lag, and recovery time. Prefer bounded, resumable work.
- Dropping old structures immediately: Old code, delayed jobs, or reporting queries may still reference them.
- Testing only on an empty database: Table size, data distribution, indexes, and concurrent traffic often determine the real risk.
- Assuming migration tools guarantee safety: A framework can track versions and standardize execution, but it cannot know your traffic pattern or application dependencies automatically.
- Relying on an untested down migration: Reverse scripts may fail after data has been transformed or deleted. Treat them as code that requires review and testing.
- Ignoring scheduled work: Cron jobs and workers can execute old queries during a release. Review schedules using the Cron Expression Guide when timing or time zones affect the deployment.
- Skipping application-level checks: A successful SQL command does not prove that APIs, forms, reports, or background jobs still behave correctly.
When to revisit
Use this checklist before every production schema change, not only before major releases. Revisit the plan when table size, write volume, deployment strategy, database version, migration framework, hosting provider, or backup process changes. It is also worth reviewing after an incident, a failed migration, a framework upgrade, or a change in seasonal traffic patterns.
For the next migration, create a short deployment record with these fields:
- Migration purpose and affected objects.
- Compatibility plan for old and new application versions.
- Expected locks, duration, load, and abort thresholds.
- Backup or restore reference and owner.
- Validation queries and monitoring dashboard.
- Stop, rollback, or roll-forward procedure.
- Post-deployment cleanup date for temporary columns, dual writes, and old indexes.
Run the migration in a production-like environment, rehearse the recovery path, and deploy the smallest safe step first. Afterward, record actual duration, observed locks, data-validation results, and any follow-up work. That record turns each migration into practical evidence for the next one and helps keep your backend deployment process dependable.