Introduction to Prisma Migrations
Add rollback and programmatic control to Prisma migrations
What is Prisma Migrations?
If you’re using Prisma but miss having rollback and programmatic migration control like other ORMs, this tool fills those gaps. It wraps Prisma’s migration system and adds the features that should have been there from the start.
The Problem
Prisma’s prisma migrate works well for forward migrations, but has some limitations:
- No rollback - Once a migration is applied, there’s no built-in way to undo it
- No programmatic API - You can’t run migrations from your Node.js code
- Limited control - Can’t run specific numbers of migrations or choose which to apply
Meanwhile, pretty much every other ORM (Knex, TypeORM, Sequelize, Rails, Laravel) has had these features for years.
When you hit these limitations in production, you’re stuck manually writing SQL or working around Prisma’s constraints.
The Solution
This tool wraps Prisma and adds what’s missing:
| Feature | Prisma Migrate | prisma-migrations |
|---|---|---|
| Run migrations forward | ✓ | ✓ |
| Deploy to production | ✓ | ✓ |
| Rollback migrations | ✗ | ✓ |
| Run from Node.js code | ✗ | ✓ |
| Step-by-step control | ✗ | ✓ |
| Interactive mode | ✗ | ✓ |
| Up/down migrations | ✗ | ✓ |
Key point: This is 100% compatible with Prisma. It uses Prisma’s standard _prisma_migrations table and works alongside prisma migrate commands.
Quick Example
CLI Usage
# Create a migration
npx prisma-migrations create add_users
# Run migrations
npx prisma-migrations up
# Rollback when needed
npx prisma-migrations down
Migration File
-- Migration: Up
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
created_at TIMESTAMP DEFAULT NOW()
);
-- Migration: Down
DROP TABLE IF EXISTS users;
Programmatic API
import { Migrations } from 'prisma-migrations';
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
const migrations = new Migrations(prisma);
// Run all pending migrations
await migrations.up();
// Rollback last migration
await migrations.down();
Key Features
- Rollback support - Up and down migrations like other ORMs
- Programmatic API - Run migrations from your Node.js/TypeScript code
- Step control - Run or rollback N migrations at a time
- Interactive mode - Choose which migrations to apply
- SQL migrations - Standard SQL format with up/down sections
- Zero config - Works out of the box with existing Prisma projects
- Prisma compatible - Uses Prisma’s
_prisma_migrationstable
When to Use This
Use this tool if:
- You need to rollback migrations (especially in production)
- You want to run migrations programmatically
- You want step-by-step control over migrations
- You’re coming from Knex/TypeORM/etc and miss those features
Use Prisma Migrate if:
- You only ever need forward migrations
- CLI-only execution is fine for you
- You don’t need rollback
Both can coexist - they use the same migration table.
Next Steps
- Installation & Quick Start - Get started in 5 minutes
- Code Labs - Step-by-step tutorials
- API Reference - Full documentation