Get started with Prisma Migrate
This page explains how to get started with migrating your schema in a development environment using Prisma Migrate. See Developing with Prisma Migrate for a more in-depth development workflow.
Get started with Prisma Migrate
To get started with Prisma Migrate in a development environment:
Create a Prisma schema:
schema.prisma1datasource db {2 provider = "postgresql"3 url = env("DATABASE_URL")4}56model User {7 id Int @id @default(autoincrement())8 name String9 posts Post[]10}1112model Post {13 id Int @id @default(autoincrement())14 title String15 published Boolean @default(true)16 authorId Int17 author User @relation(fields: [authorId], references: [id])18}You can use native type mapping attributes in your schema to decide which exact database type to create (for example,
String
can map tovarchar(100)
ortext
).- Create the first migration:
$prisma migrate dev --name initShow migration SQLYour Prisma schema is now in sync with your database schema and you have initialized a migration history:
migrations/└─ 20210313140442_init/└─ migration.sqlAdd additional fields to your schema:
model User {id Int @id @default(autoincrement())jobTitle Stringname Stringposts Post[]}Create the second migration:
$prisma migrate dev --name added_job_titleShow migration SQLYour Prisma schema is once again in sync with your database schema, and your migration history contains two migrations:
migrations/└─ 20210313140442_init/└─ migration.sql└─ 20210313140442_added_job_title/└─ migration.sql
You now have a migration history that you can source control and use to deploy changes to test environments and production.