diff --git a/content/200-orm/300-prisma-migrate/050-getting-started.mdx b/content/200-orm/300-prisma-migrate/050-getting-started.mdx index 7e7e24acba..f56a1a607e 100644 --- a/content/200-orm/300-prisma-migrate/050-getting-started.mdx +++ b/content/200-orm/300-prisma-migrate/050-getting-started.mdx @@ -14,17 +14,20 @@ To get started with Prisma Migrate in a development environment: 1. Create a Prisma schema: + + + ```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 @@ -34,15 +37,58 @@ To get started with Prisma Migrate in a development environment: } ``` + + + + + + ```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]) + } + ``` + + + + :::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: @@ -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 { @@ -105,7 +152,7 @@ To get started with Prisma Migrate in a development environment: } ``` -1. Create the second migration: +3. Create the second migration: @@ -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`. \ No newline at end of file