Prisma 2 supports a development mode which can be launched using the prisma2 dev
command. When in development mode, Prisma 2 runs a development server in the background that watches your Prisma schema file.
Whenever you save any changes in the schema file, the development server:
- (re)generates your data source clients (e.g. Photon)
- updates your database schema (read below)
- creates a Prisma Studio endpoint for you
Depending on whether you're using only Photon or only Lift, it might only perform one of the above tasks.
You can start the development mode by with the following command of the Prisma 2 CLI:
prisma2 dev
You can stop the development mode by hitting CTRL+C two times.
Typically, when you're using Lift for database migrations, a migration is performed as a 3-step process:
- Adjust data model: Change your data model definition to match your desired database schema.
- Save migration: Run
prisma2 lift save
to create your migration files on the file system. - Run migration: Run
prisma2 lift up
to perform the migration against your database.
This is not how migrations are performed in development mode! When running in development mode, there is only one step:
- Adjust data model: Change your data model definition to match your desired database schema. Then save the schema file.
Because the development server is watching your schema file (which includes the data model definition) in the background, it notices that you've performed a change and updates your database schema for you. The migration files created for this schema update are stored in the migrations/dev
directory. However, it does update Lift's _Migrations
table in your database schema.
The development mode lets you make quick changes to your data model as you develop your application without the need to persist these changes in a migration. Only once you're happy with your data model, you can stop the development mode and persist your migration using:
prisma2 lift save
prisma2 lift up
The development mode is interactive. Not only watches it your schema file, it also accepts user input as it's running. User input is typically provided by pressing a single character on your keyboard:
d
: Shows the current data model diffb
: Navigate back to previous screen