Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 54 additions & 7 deletions content/200-orm/300-prisma-migrate/050-getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ To get started with Prisma Migrate in a development environment:

1. Create a Prisma schema:

<TabbedContent code groupId="schema">
<TabItem value="Prisma 7">

```prisma file=schema.prisma showLineNumbers
datasource db {
provider = "postgresql"
}

model User {
id Int @id @default(autoincrement())
name String
posts Post[]
}

model Post {
id Int @id @default(autoincrement())
title String
Expand All @@ -34,15 +37,58 @@ To get started with Prisma Migrate in a development environment:
}
```


</TabItem>

<TabItem value="Prisma 6">

```prisma file=schema.prisma showLineNumbers
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model User {
id Int @id @default(autoincrement())
name String
posts Post[]
}

model Post {
id Int @id @default(autoincrement())
title String
published Boolean @default(true)
authorId Int
author User @relation(fields: [authorId], references: [id])
}
```

</TabItem>
</TabbedContent>

:::tip

You can use [native type mapping attributes](/orm/prisma-migrate/workflows/native-database-types) in your schema to decide which exact database type to create (for example, `String` can map to `varchar(100)` or `text`).

:::


For Prisma 7, be sure to have a `prisma.config.ts` in the root of your project:

```ts file=prisma.config.ts showLineNumbers
import 'dotenv/config'
import { defineConfig, env } from "prisma/config";
export default defineConfig({
schema: "prisma/schema.prisma",
migrations: {
path: "prisma/migrations",
},
datasource: {
url: env("DATABASE_URL"),
},
});
```

1. Create the first migration:
1. Create the first migration:

<CodeWithResult showText="Show migration SQL" hideText="Hide migration SQL">

Expand Down Expand Up @@ -91,9 +137,10 @@ To get started with Prisma Migrate in a development environment:
└─ 20210313140442_init/
└─ migration.sql
```

> **Note**: The folder name will be different for you. Folder naming is in the format of YYYYMMDDHHMMSS_your_text_from_name_flag.

1. Add additional fields to your schema:
2. Add additional fields to your schema:

```prisma highlight=3;add
model User {
Expand All @@ -105,7 +152,7 @@ To get started with Prisma Migrate in a development environment:
}
```

1. Create the second migration:
3. Create the second migration:

<CodeWithResult showText="Show migration SQL" hideText="Hide migration SQL">

Expand Down Expand Up @@ -234,4 +281,4 @@ Commit the following to source control:
## Going further

- Refer to the [Deploying database changes with Prisma Migrate](/orm/prisma-client/deployment/deploy-database-changes-with-prisma-migrate) guide for more on deploying migrations to production.
- Refer to the [Production Troubleshooting](/orm/prisma-migrate/workflows/patching-and-hotfixing#fixing-failed-migrations-with-migrate-diff-and-db-execute) guide to learn how to debug and resolve failed migrations in production using `prisma migrate diff`, `prisma db execute` and/ or `prisma migrate resolve`.
- Refer to the [Production Troubleshooting](/orm/prisma-migrate/workflows/patching-and-hotfixing#fixing-failed-migrations-with-migrate-diff-and-db-execute) guide to learn how to debug and resolve failed migrations in production using `prisma migrate diff`, `prisma db execute` and/ or `prisma migrate resolve`.
Loading