From b71abebc9fea84b8b295531d30789ea76c070fe8 Mon Sep 17 00:00:00 2001 From: Mike Hartington Date: Thu, 20 Nov 2025 15:47:02 -0500 Subject: [PATCH 1/2] docs(): update migration getting started --- .../050-getting-started.mdx | 173 +++++++++++------- 1 file changed, 110 insertions(+), 63 deletions(-) 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..58edf21fe2 100644 --- a/content/200-orm/300-prisma-migrate/050-getting-started.mdx +++ b/content/200-orm/300-prisma-migrate/050-getting-started.mdx @@ -14,84 +14,131 @@ 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 - published Boolean @default(true) - authorId Int - author User @relation(fields: [authorId], references: [id]) - } - ``` + + + +```prisma file=schema.prisma showLineNumbers +datasource db { + provider = "postgresql" +} + +model User { + id Int @id @default(autoincrement()) + name String + posts Post[] +} - :::tip +model Post { + id Int @id @default(autoincrement()) + title String + published Boolean @default(true) + authorId Int + author User @relation(fields: [authorId], references: [id]) +} +``` - 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`). - ::: + - + - 1. Create the first migration: +```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]) +} +``` - ```terminal - prisma migrate dev --name init - ``` + + - +:::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`). - ```sql no-copy - -- CreateTable - CREATE TABLE "User" ( - "id" SERIAL, - "name" TEXT NOT NULL, - - PRIMARY KEY ("id") - ); - -- CreateTable - CREATE TABLE "Post" ( - "id" SERIAL, - "title" TEXT NOT NULL, - "published" BOOLEAN NOT NULL DEFAULT true, - "authorId" INTEGER NOT NULL, - - PRIMARY KEY ("id") - ); - - -- AddForeignKey - ALTER TABLE "Post" ADD FOREIGN KEY("authorId")REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; - ``` +::: - +For Prisma 7, be sure to have a `prisma.config.ts` in the root of your project: - > **Note**: If you do not provide a `--name`, Prisma CLI will prompt you for a name. +```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: - Your Prisma schema is now in sync with your database schema and you have initialized a migration history: + - ``` - migrations/ - └─ 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. + + + ```terminal + prisma migrate dev --name init + ``` + + + + + + ```sql no-copy + -- CreateTable + CREATE TABLE "User" ( + "id" SERIAL, + "name" TEXT NOT NULL, + + PRIMARY KEY ("id") + ); + -- CreateTable + CREATE TABLE "Post" ( + "id" SERIAL, + "title" TEXT NOT NULL, + "published" BOOLEAN NOT NULL DEFAULT true, + "authorId" INTEGER NOT NULL, + + PRIMARY KEY ("id") + ); + + -- AddForeignKey + ALTER TABLE "Post" ADD FOREIGN KEY("authorId")REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + ``` + + + + > **Note**: If you do not provide a `--name`, Prisma CLI will prompt you for a name. + + + + Your Prisma schema is now in sync with your database schema and you have initialized a migration history: + + ``` + migrations/ + └─ 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: @@ -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 From fb1406e7082e80db767558678f664bb78ace9f90 Mon Sep 17 00:00:00 2001 From: Mike Hartington Date: Thu, 20 Nov 2025 15:59:50 -0500 Subject: [PATCH 2/2] docs(): fix formatting --- .../050-getting-started.mdx | 200 +++++++++--------- 1 file changed, 100 insertions(+), 100 deletions(-) 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 58edf21fe2..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,133 +14,133 @@ 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 - published Boolean @default(true) - authorId Int - author User @relation(fields: [authorId], references: [id]) -} -``` - - - + ```prisma file=schema.prisma showLineNumbers + datasource db { + provider = "postgresql" + } - + model User { + id Int @id @default(autoincrement()) + name String + posts Post[] + } -```prisma file=schema.prisma showLineNumbers -datasource db { - provider = "postgresql" - url = env("DATABASE_URL") -} + model Post { + id Int @id @default(autoincrement()) + title String + published Boolean @default(true) + authorId Int + author User @relation(fields: [authorId], references: [id]) + } + ``` -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 + ```prisma file=schema.prisma showLineNumbers + datasource db { + provider = "postgresql" + url = env("DATABASE_URL") + } -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`). + 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]) + } + ``` -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"), - }, -}); -``` + :::tip - 1. Create the first migration: + 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"), + }, + }); + ``` - ```terminal - prisma migrate dev --name init - ``` +1. Create the first migration: - + - + - ```sql no-copy - -- CreateTable - CREATE TABLE "User" ( - "id" SERIAL, - "name" TEXT NOT NULL, + ```terminal + prisma migrate dev --name init + ``` - PRIMARY KEY ("id") - ); - -- CreateTable - CREATE TABLE "Post" ( - "id" SERIAL, - "title" TEXT NOT NULL, - "published" BOOLEAN NOT NULL DEFAULT true, - "authorId" INTEGER NOT NULL, + - PRIMARY KEY ("id") - ); + - -- AddForeignKey - ALTER TABLE "Post" ADD FOREIGN KEY("authorId")REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; - ``` + ```sql no-copy + -- CreateTable + CREATE TABLE "User" ( + "id" SERIAL, + "name" TEXT NOT NULL, + + PRIMARY KEY ("id") + ); + -- CreateTable + CREATE TABLE "Post" ( + "id" SERIAL, + "title" TEXT NOT NULL, + "published" BOOLEAN NOT NULL DEFAULT true, + "authorId" INTEGER NOT NULL, + + PRIMARY KEY ("id") + ); + + -- AddForeignKey + ALTER TABLE "Post" ADD FOREIGN KEY("authorId")REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + ``` - + - > **Note**: If you do not provide a `--name`, Prisma CLI will prompt you for a name. + > **Note**: If you do not provide a `--name`, Prisma CLI will prompt you for a name. - + - Your Prisma schema is now in sync with your database schema and you have initialized a migration history: + Your Prisma schema is now in sync with your database schema and you have initialized a migration history: - ``` - migrations/ - └─ 20210313140442_init/ - └─ migration.sql - ``` + ``` + migrations/ + └─ 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. + > **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 { @@ -152,7 +152,7 @@ export default defineConfig({ } ``` -1. Create the second migration: +3. Create the second migration: