Skip to content

Commit 3abdbc4

Browse files
committed
docs(): update migration getting started
1 parent e8d4bde commit 3abdbc4

File tree

1 file changed

+107
-61
lines changed

1 file changed

+107
-61
lines changed

content/200-orm/300-prisma-migrate/050-getting-started.mdx

Lines changed: 107 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -14,83 +14,129 @@ To get started with Prisma Migrate in a development environment:
1414

1515
1. Create a Prisma schema:
1616

17-
```prisma file=schema.prisma showLineNumbers
18-
datasource db {
19-
provider = "postgresql"
20-
}
21-
22-
model User {
23-
id Int @id @default(autoincrement())
24-
name String
25-
posts Post[]
26-
}
27-
28-
model Post {
29-
id Int @id @default(autoincrement())
30-
title String
31-
published Boolean @default(true)
32-
authorId Int
33-
author User @relation(fields: [authorId], references: [id])
34-
}
35-
```
17+
<TabbedContent code groupId="schema">
18+
<TabItem value="Prisma 7">
19+
20+
```prisma file=schema.prisma showLineNumbers
21+
datasource db {
22+
provider = "postgresql"
23+
}
24+
25+
model User {
26+
id Int @id @default(autoincrement())
27+
name String
28+
posts Post[]
29+
}
3630
37-
:::tip
31+
model Post {
32+
id Int @id @default(autoincrement())
33+
title String
34+
published Boolean @default(true)
35+
authorId Int
36+
author User @relation(fields: [authorId], references: [id])
37+
}
38+
```
3839

39-
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`).
4040

41-
:::
41+
</TabItem>
4242

43-
43+
<TabItem value="Prisma 6">
4444

45-
1. Create the first migration:
45+
```prisma file=schema.prisma showLineNumbers
46+
datasource db {
47+
provider = "postgresql"
48+
url = env("DATABASE_URL")
49+
}
4650
47-
<CodeWithResult showText="Show migration SQL" hideText="Hide migration SQL">
51+
model User {
52+
id Int @id @default(autoincrement())
53+
name String
54+
posts Post[]
55+
}
4856
49-
<cmd>
57+
model Post {
58+
id Int @id @default(autoincrement())
59+
title String
60+
published Boolean @default(true)
61+
authorId Int
62+
author User @relation(fields: [authorId], references: [id])
63+
}
64+
```
5065

51-
```terminal
52-
prisma migrate dev --name init
53-
```
66+
</TabItem>
67+
</TabbedContent>
5468

55-
</cmd>
69+
:::tip
5670

57-
<cmdResult>
71+
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`).
5872

59-
```sql no-copy
60-
-- CreateTable
61-
CREATE TABLE "User" (
62-
"id" SERIAL,
63-
"name" TEXT NOT NULL,
64-
65-
PRIMARY KEY ("id")
66-
);
67-
-- CreateTable
68-
CREATE TABLE "Post" (
69-
"id" SERIAL,
70-
"title" TEXT NOT NULL,
71-
"published" BOOLEAN NOT NULL DEFAULT true,
72-
"authorId" INTEGER NOT NULL,
73-
74-
PRIMARY KEY ("id")
75-
);
76-
77-
-- AddForeignKey
78-
ALTER TABLE "Post" ADD FOREIGN KEY("authorId")REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
79-
```
73+
:::
8074

81-
</cmdResult>
75+
For Prisma 7, be sure to have a `prisma.config.ts` in the root of your project:
8276

83-
> **Note**: If you do not provide a `--name`, Prisma CLI will prompt you for a name.
77+
```ts file=prisma.config.ts showLineNumbers
78+
import 'dotenv/config'
79+
import { defineConfig, env } from "prisma/config";
80+
export default defineConfig({
81+
schema: "prisma/schema.prisma",
82+
migrations: {
83+
path: "prisma/migrations",
84+
},
85+
datasource: {
86+
url: env("DATABASE_URL"),
87+
},
88+
});
89+
```
8490

85-
</CodeWithResult>
91+
1. Create the first migration:
8692

87-
Your Prisma schema is now in sync with your database schema and you have initialized a migration history:
93+
<CodeWithResult showText="Show migration SQL" hideText="Hide migration SQL">
8894

89-
```
90-
migrations/
91-
└─ 20210313140442_init/
92-
└─ migration.sql
93-
```
95+
<cmd>
96+
97+
```terminal
98+
prisma migrate dev --name init
99+
```
100+
101+
</cmd>
102+
103+
<cmdResult>
104+
105+
```sql no-copy
106+
-- CreateTable
107+
CREATE TABLE "User" (
108+
"id" SERIAL,
109+
"name" TEXT NOT NULL,
110+
111+
PRIMARY KEY ("id")
112+
);
113+
-- CreateTable
114+
CREATE TABLE "Post" (
115+
"id" SERIAL,
116+
"title" TEXT NOT NULL,
117+
"published" BOOLEAN NOT NULL DEFAULT true,
118+
"authorId" INTEGER NOT NULL,
119+
120+
PRIMARY KEY ("id")
121+
);
122+
123+
-- AddForeignKey
124+
ALTER TABLE "Post" ADD FOREIGN KEY("authorId")REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
125+
```
126+
127+
</cmdResult>
128+
129+
> **Note**: If you do not provide a `--name`, Prisma CLI will prompt you for a name.
130+
131+
</CodeWithResult>
132+
133+
Your Prisma schema is now in sync with your database schema and you have initialized a migration history:
134+
135+
```
136+
migrations/
137+
└─ 20210313140442_init/
138+
└─ migration.sql
139+
```
94140

95141
1. Add additional fields to your schema:
96142

0 commit comments

Comments
 (0)