migration plan
Plan an on-disk migration from Prisma 8 contract changes.
migration plan compares the emitted contract against a starting contract and produces a new migration package with the required operations.
The starting contract is the ref named db when one exists, or whatever --from names. With neither, the plan starts from nothing and contains the full CREATE operations for the whole contract, so keep the db ref pointing at the migration your database is on (apply with db migrate --advance-ref db to move it automatically), or pass --from explicitly.
The command is offline. It does not need a database connection.
Usage
bunx prisma@latest migration plan --name add-users-tableOptions
| Option | What it does |
|---|---|
--name <slug> | Sets the migration directory name suffix. |
--from <contract> | Uses a specific starting contract reference (hash, prefix, ref name, migration directory name, <dir>^, or ./path) instead of the latest migration target. |
--to <contract> | Sets the destination contract reference. Defaults to the emitted contract. Same grammar as --from. |
--config <path> | Read this config file instead of ./prisma.config.ts. |
--json | Prints a machine-readable result. |
Recommended flow
bunx prisma@latest contract emit
bunx prisma@latest migration plan --name add-users-table
bunx prisma@latest migration show <migration-dir>Review the generated migration package before applying it with db migrate.
Planning a rollback
Because --to accepts <dir>^ (the source contract of a migration), you can plan a migration that walks back a change:
bunx prisma@latest migration plan --to <migration-dir>^ --name rollbackWhen to use migration plan
Use migration plan when your team wants database changes reviewed in version control. For local prototypes where review is not needed, db update is usually faster.
If the generated migration is not the migration you want, use migration new and author the migration manually.
