Zero-Downtime Database Migrations in CI/CD: A Release Checklist for Schema Changes
Database MigrationsCI/CDRelease EngineeringPostgreSQLDeployment Safety

Zero-Downtime Database Migrations in CI/CD: A Release Checklist for Schema Changes

PPlkdt Labs
2026-12-03
7 min read

A practical expand-and-contract checklist for deploying schema changes without breaking old application versions or interrupting production traffic.

Zero-downtime database migrations require more than a safe SQL statement. This release checklist shows how to change a schema while old and new application versions coexist, production traffic continues, and rollback remains possible. Use it before each migration, then adapt the checks to your database engine, ORM, deployment platform, and traffic pattern.

Overview

The safest general pattern for a live schema change is expand and contract. First, expand the database so it can support both the existing application and the new application. Next, deploy application code that uses the expanded structure without depending on the old structure being removed. After the new code is stable and old workers have drained, contract the schema by deleting obsolete columns, indexes, tables, or compatibility logic.

This sequence matters because a rolling deployment rarely replaces every application process at once. During a rollout, an old process may read or write data beside a new process. A migration that assumes every process has been updated can cause errors even when the final schema is correct.

  1. Expand: add nullable columns, new tables, compatible indexes, or dual-write fields.
  2. Backfill: copy existing data in small, observable batches.
  3. Adopt: deploy code that reads the new structure and, where necessary, writes both old and new structures.
  4. Verify: compare counts, null rates, values, latency, and error signals.
  5. Contract: stop using the old structure, then remove it in a separate change.

Keep application deployment and destructive schema removal as separate release decisions. A failed application rollout can usually be reversed more easily when the database still supports both versions.

Checklist by scenario

Before every migration

  • Write down the intended schema change, affected tables, expected row volume, and acceptable runtime.
  • Identify every application, worker, report, job, integration, and administrative script that reads or writes the affected data.
  • Confirm that a recent backup exists and that the team knows how restoration would work. A backup is not a rollback plan until restoration has been considered and, where appropriate, tested.
  • Review database capacity, replication health, connection limits, lock activity, and available disk space.
  • Define success and abort criteria before starting. Examples include an increase in write latency, replication lag, deadlocks, error rate, or lock wait time.
  • Make sure migration logs and deployment events can be correlated. A release smoke-test plan can help structure the verification phase; see Deployment Smoke Tests by Application Type.

Adding a nullable column or new table

  • Add the new object without requiring existing rows to be rewritten immediately.
  • Deploy the application so it tolerates the column or table being absent in older environments if environments are migrated independently.
  • Prefer a nullable or default-free first step when the database engine could otherwise rewrite a large table. Confirm the behavior for your exact database version.
  • Backfill in bounded batches ordered by a stable key. Pause or slow the job when database health signals degrade.
  • Only add a non-null constraint after the backfill has been checked and all writers populate the field.

Renaming a column

A direct rename can break old application processes. Use a compatibility period instead:

  1. Add the replacement column.
  2. Write new values to both columns, or use a carefully tested compatibility layer.
  3. Backfill the replacement column.
  4. Switch reads to the replacement column.
  5. Monitor for stale writers and compare both columns while dual writing remains enabled.
  6. Remove the old column only after the old application version, jobs, and rollback window have ended.

Changing a data type or meaning

Treat a type change as a data migration, not merely a DDL edit. Add a new field with the desired representation, define how invalid or ambiguous values will be handled, and migrate records in batches. During the transition, make the application explicit about which field is authoritative. Do not silently convert values when rounding, truncation, time zones, encoding, or precision could change their meaning.

Adding an index or constraint

  • Estimate index size and build time from the actual table, not just development data.
  • Use an online or concurrent index option only when supported by the database engine and appropriate for the workload.
  • Check whether the operation takes a metadata lock, blocks writes, or requires a transaction that cannot be interrupted safely.
  • For a new uniqueness constraint, find duplicates before enforcing it and decide how conflicts will be resolved.

Using a staged CI/CD deployment

A practical pipeline separates migration and application rollout into observable stages:

  1. Validate: run migration tests against a representative database and check that the migration is idempotent or safely prevented from running twice.
  2. Expand: apply additive schema changes during a controlled deployment window or as an independently monitored job.
  3. Deploy compatible code: release code that works with both the old and new schema.
  4. Backfill: run a resumable job with progress metrics, rate limits, and an operator stop switch.
  5. Adopt: enable new reads or writes, using a feature flag when the change needs gradual exposure.
  6. Verify: run data checks and application smoke tests, then observe normal traffic.
  7. Contract: remove compatibility code and obsolete schema only in a later release.

This pattern works well with blue-green or canary delivery, provided both versions remain schema-compatible. For rollout selection and rollback considerations, see Blue-Green vs Canary Deployments.

What to double-check

Backward-compatibility matrix

Schema changeOld app with new schemaNew app with old schemaSafer approach
Add nullable columnUsually compatibleUsually incompatible if the column is requiredAdd first, then deploy code that can tolerate absence where needed
Add tableUsually compatibleIncompatible if new code requires itCreate table before application rollout
Rename or remove columnOften incompatibleOften incompatibleUse a replacement field and a compatibility period
Tighten constraintCompatible only if all existing writes complyMay reject old writesClean and validate data before enforcement
Change type or semanticsDepends on reads and writesDepends on conversion logicDual fields, explicit conversion, and staged adoption

“Usually compatible” is not a guarantee. ORMs may select every column, serializers may expect a fixed shape, database views may depend on column order or names, and triggers may add hidden writes. Inspect generated SQL and integration behavior rather than relying only on migration-file intent.

Locking and runtime risks

OperationPrimary riskCheck before production
Adding a columnTable rewrite or metadata lockDatabase-version behavior, default expression, table size
Backfill updateLong transactions, bloat, replica lagBatch size, indexes, commit frequency, pause control
Building an indexHigh I/O or blocked writesOnline/concurrent support and failure behavior
Adding a uniqueness constraintDuplicate data or validation scanDuplicate query, cleanup plan, lock behavior
Dropping an objectHidden dependency or irreversible lossCode search, query logs, rollback deadline

Verification queries

Use engine-appropriate syntax and run checks that answer a specific question. For a new field named new_value, a basic completeness check is:

SELECT COUNT(*) AS missing_rows
FROM target_table
WHERE new_value IS NULL;

To compare a dual-written field pair, adapt the comparison to the fields’ type and normalization rules:

SELECT COUNT(*) AS mismatches
FROM target_table
WHERE old_value IS DISTINCT FROM new_value;

IS DISTINCT FROM is available in some relational databases, including PostgreSQL; use the equivalent null-safe comparison for your engine. To check for duplicate values before adding uniqueness:

SELECT candidate_key, COUNT(*) AS row_count
FROM target_table
GROUP BY candidate_key
HAVING COUNT(*) > 1;

Also verify application-level outcomes: successful writes, read-after-write behavior, background jobs, queue consumers, reporting queries, and rollback readiness. Database counts alone cannot confirm that every client interprets the new schema correctly.

Common mistakes

  • Combining expand and contract in one release. This removes the safety window needed for rolling deployments and rollback.
  • Backfilling in one giant transaction. Large transactions can hold locks, consume resources, create replication lag, and make cancellation expensive.
  • Assuming a migration tool handles operational risk. A tool can order and record migrations, but it does not know your traffic pattern, hidden consumers, or acceptable lock duration.
  • Making a field required too early. Existing rows, delayed jobs, and old application instances may still omit it.
  • Removing compatibility code immediately after deployment. Delayed workers, cached processes, and rollback procedures may still depend on the old path.
  • Testing only the final schema. Test intermediate states: old code with expanded schema, new code with expanded schema, partial backfill, and interrupted migration.
  • Calling backup restoration a routine rollback. Restoration can cause downtime and data loss relative to the recovery point. Prefer forward-compatible changes and a tested recovery procedure.
  • Ignoring operational dependencies. Connection pools, secrets, deployment variables, and observability changes can affect a migration just as much as SQL. Review the CI/CD environment and secrets checklist when pipeline behavior changes.

When to revisit

Revisit this checklist before every production schema change, not only before large releases. Repeat the design review when table size, traffic, replication topology, database version, ORM behavior, migration tooling, or deployment strategy changes. A migration that was low risk on a small single-region database may require a different batch size, index strategy, or rollout sequence after growth.

Before seasonal planning cycles, review migration runbooks, restore procedures, access permissions, alert thresholds, and the age of compatibility code. After an incident or failed migration, record the observed lock duration, batch throughput, replica impact, and application symptoms. Turn those observations into explicit preflight and abort criteria.

For the next migration, copy this short action list into the release ticket:

  1. Describe the expand, adopt, verify, and contract steps.
  2. List every reader and writer, including jobs and integrations.
  3. Test old and new application versions against each intermediate schema.
  4. Choose batch limits and define a stop condition.
  5. Record verification queries and expected results.
  6. Confirm monitoring, backup recovery, and the point at which rollback changes to forward repair.
  7. Schedule destructive cleanup only after the compatibility window has closed.

That discipline turns database migration from a one-time SQL task into a controlled deployment process: observable, reversible where possible, and safer to repeat.

Related Topics

#Database Migrations#CI/CD#Release Engineering#PostgreSQL#Deployment Safety
P

Plkdt Labs

Editorial Engineering Team

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.