---
title: Database Migration
category: product
entity_type: skill
price: $15
canonical: https://forgehouse.ai/skills/database-migration/
lang: en
hreflang_alt: https://forgehouse.ai/tr/skiller/database-migration/
last_updated: 2026-06-20
---

# Database Migration

> Execute database migrations across ORMs and platforms with zero-downtime strategies, data…

A cross-ORM, cross-platform guide for executing database migrations safely: across Sequelize, TypeORM, and Prisma: with zero-downtime strategies, data transformations, and tested rollback procedures. It teaches the expand-contract pattern so schema changes never take the application down, and wraps changes in transactions and checkpoints so nothing is left half-applied.

## Use cases
- Renaming or retyping a column on a large table without downtime
- Migrating schema or data between ORMs (Sequelize, TypeORM, Prisma)
- Splitting one column into several with a complex data transformation
- Running a blue-green deployment with a backward-compatible schema
- Handling dialect differences when migrating between PostgreSQL and MySQL
- Building checkpoint-based rollback with backup tables and verification

## Benefits
- Change production schemas with zero downtime using the expand-contract pattern
- Recover safely from a failed migration with transaction wrapping and checkpoint backups
- Avoid data loss by handling NULL defaults, foreign keys, and verification correctly
- Reduce blast radius by splitting big changes into small, independently reversible steps

## What’s included
- Side-by-side migration examples for Sequelize, TypeORM, and Prisma
- Schema transformation patterns: add-with-default, zero-downtime rename, type change
- A complex data-migration example that parses and splits a field, with a symmetric rollback
- Transaction-based and checkpoint-based rollback strategies with backup tables
- A five-phase blue-green deployment sequence for renaming a column live
- Cross-database dialect handling, best practices, and a common-pitfalls list

## Who it’s for
Backend developers and DBAs running schema or data migrations who need zero downtime and reliable rollback.

## How it runs
Schema changes are treated like surgery here: small incisions, a tested rollback for every cut, and a backup taken before production is touched. Expand-contract keeps the database live while the change lands.
1. Cuts the change into single-responsibility migrations: ten column changes never share one file, because if the seventh fails the first six must roll back too; small migrations mean a small blast radius and a fast revert.
2. Writes every up() with a symmetric down() and idempotency guards (IF EXISTS, IF NOT EXISTS, column presence checks), so a migration can be re-run after an emergency rollback without erroring out.
3. Runs destructive or multi-step changes inside a transaction, and respects the engine difference: PostgreSQL DDL is transactional, MySQL DDL commits implicitly, which changes the safety plan on cross-database work.
4. Uses expand-contract for zero downtime: add the new column, backfill, deploy code that writes to both, deploy code that reads from the new one, and only then drop the old column in a separate later migration.
5. Takes a checkpoint before production: a backup table or a full dump created first, the migration verified with a count query afterwards, and on failure the table is restored from the backup instead of hoping down() works.
6. Adds defaults before NOT NULL constraints, handles NULLs explicitly in data transformations, and tests the rollback path on staging, because an untested down() is not a rollback plan.

## FAQ
### We use a different ORM than the three named. Are these strategies still usable?
The expand-contract pattern and rollback discipline are ORM-agnostic, so the strategy carries even where the named examples for Sequelize, TypeORM, and Prisma do not match your tool. You translate the mechanics; the safe sequence stays the same.

### Does expand-contract really avoid downtime, or just shorten it?
Done in order, expand then migrate then contract, the app keeps reading and writing throughout, so there is no required outage window. The trade is that you live with both the old and new shapes for a stretch, not that you accept a short downtime.

### Does it run the migration against production for me?
It is a strategy and rollback guide, not an automated runner, so you execute the steps on your own infrastructure. A large data backfill still takes the time and compute your table size demands, regardless of how clean the plan is.

## Price
$15, one-time, no subscription. VAT included.

Related guide: [AI for data analytics](https://forgehouse.ai/guides/ai-data-analytics/)
