This page helps you make an informed decision on when and how to upgrade from Prisma 1 to Prisma version 2.x and later.
The upgrade documentation consists of several pages, here's an overview of how to use them:
- How to upgrade (you are here): Starting point to learn about the upgrade process in general.
- Schema incompatibilities: A reference page about the schema incompatibilities between Prisma 1 and Prisma 2.x (and later versions). Reading this page is optional but it will give you a better understanding of certain steps in the upgrade process.
In addition to these two pages, there are various practical guides that walk you through an example scenario of the upgrade process:
- Upgrading the Prisma layer: No matter what your Prisma 1 setup looks like, you should always start your upgrade process by following this guide.
Once you're done with that guide, you can choose one of the following four guides to upgrade your application layer:
- Old to new Nexus: Choose this guide if you're currently running Prisma 1 with GraphQL Nexus.
- prisma-binding to Nexus: Choose this guide if you're currently running Prisma 1 with
prisma-bindingand want to upgrade to Nexus.
- prisma-binding to SDL-first: Choose this guide if you're currently running Prisma 1 with
prisma-bindingand want to upgrade to an SDL-first GraphQL server.
- REST API: Choose this guide if you're currently running Prisma 1 using Prisma Client 1 and are building a REST API.
On a high-level, the biggest differences between Prisma 1 and Prisma versions 2.x and later are summarized below.
Prisma 2.x and later versions:
- don't require hosting a database proxy server (i.e., the Prisma server).
- make the features of Prisma 1 more modular and splits them into dedicated tools:
- Prisma Client: An improved version of Prisma Client 1.0
- Prisma Migrate: Data modeling and migrations (formerly
- use the Prisma schema, a merge of Prisma 1 datamodel and
- use its own modeling language instead of being based on GraphQL SDL.
- don't expose "a GraphQL API for your database" anymore, but only allows for programmatic access via the Prisma Client API.
- don't support Prisma binding any more.
- allows connecting Prisma 2.x and later version to any existing database, via more powerful introspection
Prisma 2.x and later versions do not yet have full feature parity with Prisma 1. The biggest feature that is still missing from Prisma versions 2.x and later is real-time subscriptions.
- Real-time API (Subscriptions): Prisma version 2.x and later currently doesn't have a way to subscribe to events happening in the database and get notified in real time. It is currently unclear if, when, and in what form a real-time API will be added to Prisma versions 2.x and later. For the time being, you can implement real-time functionality using native database triggers, or if you're using GraphQL subscriptions you can consider triggering subscriptions manually inside your mutation resolvers.
The database schema that is created when running
prisma deploy in Prisma 1 is only partially compatible with the one that Prisma versions 2.x and later creates. This section gives a quick overview of the general incompatibilities and the potential workarounds. -
Note: For a detailed explanation of the problems and respective workarounds, please refer to the Schema incompatibilities page.
Here's an overview of the different columns:
- Problem: A short description of the problem when upgrading from Prisma 1 to Prisma versions 2.x and later
- SQL: Can this be solved by making a non-breaking change to the SQL schema?
- Prisma schema: Can this be solved by making a non-breaking change to the schema in Prisma versions 2.x and later?
- Breaking Prisma 1: Do the SQL statements break the Prisma 1 setup? This is only relevant when you're choosing the gradual side-by-side upgrade strategy.
|Problem||SQL||Prisma schema||Breaking Prisma 1|
|Default values aren't represented in database||Yes||Yes||No|
|Generated CUIDs as ID values aren't represented in database||No||Yes||No|
|Inline 1-1 relations are recognized as 1-n (missing ||Yes||No||No|
|All non-inline relations are recognized as m-n||Yes||No||Yes|
|Json type is represented as ||Yes||No||No (MySQL) |
|Enums are represented as ||Yes||No||No (MySQL) |
|Required 1-1 relations are not represented in database||No||Yes||No|
|Mismatching CUID length||Yes||No||No|
|Scalar lists (arrays) are maintained with extra table||Depends||No||Depends|
Note: A general drawback with the workarounds in the Prisma schema is that changes to the Prisma schema get lost after re-introspecting the database and need to be re-added manually after each introspection run.
The Prisma 1 Upgrade CLI helps you apply the workarounds that are explained on the Schema incompatibilities page. It generates the SQL statements to fix the database schema and make it compatible with Prisma versions 2.x and later. Note that you are in full control over the operations that are executed against your database, the Upgrade CLI only generates and prints the statements for you. The Upgrade CLI also takes care of the workarounds in the Prisma schema.
On a high-level, the upgrade workflow using the Upgrade CLI looks as follows.
For the initial setup:
- You set up Prisma by installing the Prisma versions 2.x and later CLI and running
npx prisma init.
- You connect to your database and introspect it with
npx prisma db pull.
For fixing the schema incompatibilities:
- You invoke the Upgrade CLI with
- The Upgrade CLI generates SQL commands for you to run on your database.
- You run the SQL commands against your database.
- You run the
prisma db pullcommand again.
- You run the
npx prisma-upgradecommand again.
- The Upgrade CLI adjusts the Prisma schema (version 2.x and later) by adding missing attributes.
Note that the Upgrade CLI is designed in a way that you can stop and re-start the process at any time. Once you ran a SQL command that was generated by the Upgrade CLI against your database, the SQL command will not show up the next time you invoke the Upgrade CLI. That way, you can gradually resolve all schema incompatibilities when it's convenient for you.
There are two main upgrade strategies:
- Upgrade all at once: Entirely remove Prisma 1 from your project and move everything over to Prisma version 2.x or later at once.
- Gradual upgrade side-by-side: Add Prisma version 2.x and later to the existing Prisma 1 project and gradually replace existing Prisma 1 features with the newer Prisma features while running them side-by-side.
Note that if you are planning to run Prisma 1 and Prisma 2.x or later version side-by-side, you must not yet resolve the schema compatibilities that are breaking the Prisma 1 setup.
If your project is not yet running in production or has little traffic and user data, the all at once strategy is recommended.
In case your project already sees a lot of traffic and has a lot of user data stored in the database, you might want to consider the gradual upgrade strategy where you're running Prisma 1 and Prisma 2 or later side-by-side for a certain amount of time until you've replace all former Prisma 1 functionality with Prisma 2 or later version.
Note that you won't be able to fix the schema incompatibilities that require a "Breaking Prisma 1" change if you choose the gradual upgrade strategy and intend to run Prisma 1 and Prisma version 2.x or later side-by-side. That's because these data migrations are breaking the schema that Prisma 1 expects. This means that your Prisma Client API might not feel as idiomatic as it could, but you still get the full feature set of Prisma Client.
No matter which of the strategies you choose, on a high-level the envisioned upgrade path looks as follows:
- Install the new Prisma version 2.x or later CLI as a development dependency
- Create your Prisma schema and configure the database connection URL
- Use the Prisma version 2.x or later CLI to introspect your Prisma 1 database and generate your Prisma schema
- Run the Prisma 1 Upgrade CLI to "fix" the Prisma schema
- Install and generate Prisma Client version 2.x or later
- Adjust your application code, specifically replace the API calls from the Prisma Client 1.0 with those of Prisma Client version 2.x or later
Once you've made the decision to upgrade, continue with the Upgrading the Prisma layer guide.