Schema
Learn how to update your database schema and migrate changes with Prisma.
The database schema is defined in packages/database/prisma/schema.prisma. This schema file uses Prisma’s schema definition language to describe your database tables, relationships, and types.
Update
To update your database schema, you can edit the schema.prisma file located in the /packages/database package. More information about the Prisma schema file can be found here.
For example we can add a new field businessPhone to the Contact model.
model Contact { // ... businessPhone String? // ...}That's it, we have defined a new field. The field is an optional string with a max length of 32 characters. Now let's inform the database about the change using a migration.
Migration
Create a new migration by running the following command:
pnpm --filter database migrateThis will keep a migration history of your database changes. Prisma creates a new migrations under packages/database/migrations.
Push changes to the database
To apply your schema changes to the database, run:
pnpm --filter database pushAfter the migration is applied, Prisma creates a new migration history record in the database.
Generate prisma client
After pushing your schema changes, re-generate the Prisma client by running:
pnpm --filter database generateThis command will automatically be executed when you start the development server or build the project.
Good to know: The Typescript server has sometimes problems with re-discovering the newly generated type definitions. Restarting VS Code usually does the trick - alternatively you can also restart the Typescript server.