Production Migration Workflow
Deploying database migrations in CI/CD pipelines, Docker containers, Kubernetes jobs, and zero-downtime database release strategies.
Production Migration Workflow
Deploying database migrations to production environments requires automated, non-interactive execution with zero downtime.
1. The Production Rule: migrate deploy
In production, always run prisma migrate deploy instead of prisma migrate dev.
npx prisma migrate deploy- Non-interactive (will never prompt to reset the database).
- Applies only pending migrations that have not yet been executed.
- Fails with a non-zero exit code if a migration error occurs, halting CI/CD deployments before bad code goes live.
2. Running Migrations in GitHub Actions CI/CD
# .github/workflows/deploy.yml
name: Deploy Production
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run Database Migrations
env:
DATABASE_URL: ${{ secrets.PRODUCTION_DATABASE_URL }}
run: npx prisma migrate deploy
- name: Build Application
run: pnpm build3. Docker Container Entrypoint Pattern
When running in Docker, execute migrations inside an entrypoint script before starting the Node server:
#!/bin/sh
# docker-entrypoint.sh
set -e
echo "Running database migrations..."
npx prisma migrate deploy
echo "Starting application server..."
exec node dist/index.js4. Zero-Downtime Migration Principles
To avoid breaking active traffic during deployments:
- Additive Changes First: Add new optional columns (
bio String?) before updating application code to write to them. - Never Rename Columns in One Step: Create the new column, dual-write in application code, backfill data, and drop the old column in a later release.
- Always Add Default Values: Never add a required column without a
@default(...)or nullable modifier on existing tables with data.
Related Topics
Database Seeding with Prisma
How to populate development and staging databases with mock data using prisma/seed.ts and the tsx script runner.
Prisma Connection Management & Pooling
Optimizing PostgreSQL connection pools, configuring PgBouncer, preventing connection leaks in serverless functions, and Prisma Accelerate.