diff --git a/apps/docs/content/docs/(index)/getting-started.mdx b/apps/docs/content/docs/(index)/getting-started.mdx index 59b2850fb17..25fc358a65f 100644 --- a/apps/docs/content/docs/(index)/getting-started.mdx +++ b/apps/docs/content/docs/(index)/getting-started.mdx @@ -46,7 +46,7 @@ Check the Node.js version first: `node --version` must print 22.18 or newer on t 1. Scaffold the app: `npm create prisma@latest -- my-app --template [framework] --provider postgres --yes`. 2. Get a database connection string: use the one I give you, or create a Prisma Postgres database with `npx create-db@latest` and show me the claim URL it prints. Export it as `DATABASE_URL` in the shell: in a project created with `npm create prisma`, the Prisma CLI scripts in package.json read the environment variable, not `.env`. 3. From the project directory, apply the starter contract: `npm run db:init`. The app seeds sample users on its first query, from `src/prisma/seed.ts` (`packages/database/src/seed.ts` for turborepo); there is no seed command to run. -4. Edit the starter contract under `src/prisma/` (`packages/database/src/` for turborepo) into a small schema for my use case, then run `npm run contract:emit` and plan and apply the migration: `npx prisma migration plan --name `, then `npx prisma db migrate --advance-ref db --yes`. Migration planning diffs the emitted contract, so the emit step is required. Pass `--advance-ref db` on every apply to this development database, so that the next `migration plan` starts from the state you applied; without it, the next plan repeats the last change and `db migrate` fails with `MIGRATION.PATH_UNREACHABLE`. +4. Edit the starter contract under `src/prisma/` (`packages/database/src/` for turborepo) into a small schema for my use case, then run `npm run contract:emit` and plan and apply the migration: `npx prisma migration plan --name `, then `npx prisma db migrate --yes`. Migration planning diffs the emitted contract, so the emit step is required. `db migrate` also points the `db` ref at the state you applied, so that the next `migration plan` starts from there. If it prints `MIGRATION.REF_NOT_ADVANCED_IN_CI`, the CLI found a CI variable such as `CI` in your environment and left the ref unchanged: run the command that the notice prints for a development machine, which adds `--advance-ref db`, before you plan again. 5. Update `src/prisma/seed.ts` (`packages/database/src/seed.ts` for turborepo) and the app routes to query the new schema, start `npm run dev` in the background (with `DATABASE_URL` exported), and verify with a request against the running app. For the `nest` template, if routes return 500s with `reading 'findAll'` in the logs, add explicit `@Inject()` tokens as shown in https://www.prisma.io/docs/guides/frameworks/nestjs.md. Use the installed Prisma ORM skills and the current Prisma docs: https://www.prisma.io/docs/llms.txt (append `.md` to any docs URL for a markdown version). diff --git a/apps/docs/content/docs/(index)/index.mdx b/apps/docs/content/docs/(index)/index.mdx index 0855e099619..89caec9f3e6 100644 --- a/apps/docs/content/docs/(index)/index.mdx +++ b/apps/docs/content/docs/(index)/index.mdx @@ -126,7 +126,7 @@ Check the Node.js version first: `node --version` must print 22.18 or newer on t 1. Scaffold: `npm create prisma@latest -- my-app --template [framework] --provider postgres --yes`. 2. Export my connection string as `DATABASE_URL` in the shell; the generated scripts read the environment variable, not `.env`. From the project directory: `npm run db:init`, then start `npm run dev` in the background and verify the sample query returns data. The app seeds sample users on its first query, from `src/prisma/seed.ts` (`packages/database/src/seed.ts` for turborepo); there is no seed command to run. -3. Evolve the starter contract under `src/prisma/` (`packages/database/src/` for turborepo) into my schema, then run `npm run contract:emit`, `npx prisma migration plan --name `, and `npx prisma db migrate --advance-ref db --yes`. Pass `--advance-ref db` on every apply to this development database, so that the next `migration plan` starts from the state you applied; without it, the next plan repeats the last change and `db migrate` fails with `MIGRATION.PATH_UNREACHABLE`. +3. Evolve the starter contract under `src/prisma/` (`packages/database/src/` for turborepo) into my schema, then run `npm run contract:emit`, `npx prisma migration plan --name `, and `npx prisma db migrate --yes`. `db migrate` also points the `db` ref at the state you applied, so that the next `migration plan` starts from there. Do not provision any hosted database. Use the installed Prisma ORM skills and https://www.prisma.io/docs/llms.txt for current docs. ``` diff --git a/apps/docs/content/docs/(index)/prisma-orm/add-to-existing-project/mongodb.mdx b/apps/docs/content/docs/(index)/prisma-orm/add-to-existing-project/mongodb.mdx index 207a8992dac..c391783131e 100644 --- a/apps/docs/content/docs/(index)/prisma-orm/add-to-existing-project/mongodb.mdx +++ b/apps/docs/content/docs/(index)/prisma-orm/add-to-existing-project/mongodb.mdx @@ -240,11 +240,11 @@ Before it adds a validator, `db update` checks the documents already in the coll When it succeeds, `db update` records which contract the database matches, in the database and in the file `migrations/app/refs/db.json`, called the `db` ref. `migration plan` starts from that record. Without it, `migration plan` plans every collection from an empty database, and `db migrate` then stops with `MIGRATION.PRECHECK_FAILED` because the collection already exists. If that happened to you, delete the directory that `migration plan` wrote under `migrations/app/`, run `npx prisma db update --advance-ref db`, and plan again. That plan writes only a baseline, because `db update` has already applied your change. -After that, every change follows four steps: edit `src/prisma/contract.prisma`, run `npx prisma contract emit`, run `npx prisma migration plan --name `, and run `npx prisma db migrate --advance-ref db`. Commit the `migrations/` directory. Your first `migration plan` writes two directories under `migrations/app/`: a baseline, whose name ends in `_baseline` and which describes the collections as `db update` left them, and your change. +After that, every change follows four steps: edit `src/prisma/contract.prisma`, run `npx prisma contract emit`, run `npx prisma migration plan --name `, and run `npx prisma db migrate`. Commit the `migrations/` directory. Your first `migration plan` writes two directories under `migrations/app/`: a baseline, whose name ends in `_baseline` and which describes the collections as `db update` left them, and your change. ### Production and other databases -Any other database whose collections already exist, such as production, needs the same first step before `db migrate` can run there. Leave out `--advance-ref` for those databases, because the `db` ref tracks your development database. +Any other database whose collections already exist, such as production, needs the same first step before `db migrate` can run there. Pass that database's connection string with `--db`: `db migrate` then leaves the `db` ref alone, because the ref tracks your development database. If you have not planned a migration yet, run: diff --git a/apps/docs/content/docs/(index)/prisma-orm/add-to-existing-project/postgresql.mdx b/apps/docs/content/docs/(index)/prisma-orm/add-to-existing-project/postgresql.mdx index 31284f24331..4be3743321d 100644 --- a/apps/docs/content/docs/(index)/prisma-orm/add-to-existing-project/postgresql.mdx +++ b/apps/docs/content/docs/(index)/prisma-orm/add-to-existing-project/postgresql.mdx @@ -389,7 +389,7 @@ You can ignore the word `space` in the output, because all your migrations are i Apply the migration: ```npm -npx prisma db migrate --advance-ref db +npx prisma db migrate ``` ```text no-copy @@ -406,9 +406,9 @@ App space ✔ Advanced ref "db" → 7d5976dd0655cf4b1603d0126720d50248ab95881db001c8e924291efc61f336 ``` -`db migrate` runs only the migrations that the database does not have yet. Here it adds the `phone` column, and the rows in your tables stay as they are. `marker` in the output is the record from `db sign`, which now holds the new hash. Pass `--advance-ref db` every time you apply a migration to your development database, so that the next `migration plan` contains only your next change. +`db migrate` runs only the migrations that the database does not have yet. Here it adds the `phone` column, and the rows in your tables stay as they are. `marker` in the output is the record from `db sign`, which now holds the new hash. `db migrate` also points the `db` ref at the new hash, so that the next `migration plan` contains only your next change. -To apply the migration to another database with the same tables, such as production, pass its connection string. Leave out `--advance-ref` there, because the `db` ref tracks your development database: +To apply the migration to another database with the same tables, such as production, pass its connection string. With `--db`, `db migrate` leaves the `db` ref alone, because the ref tracks your development database: ```npm npx prisma db migrate --db "$PRODUCTION_DATABASE_URL" @@ -418,7 +418,7 @@ You do not need to run `db sign` on that database. `db migrate` finds that the t ## Next steps -Every later change follows the same four steps: edit `src/prisma/contract.prisma`, run `npx prisma contract emit`, run `npx prisma migration plan --name `, and run `npx prisma db migrate --advance-ref db`. +Every later change follows the same four steps: edit `src/prisma/contract.prisma`, run `npx prisma contract emit`, run `npx prisma migration plan --name `, and run `npx prisma db migrate`. - [Generating a migration](/orm/migrations/generating-a-migration) for what a migration directory contains and how to edit it. - [`db update`](/cli/db-update) to apply a contract change to a development database without writing migration files. diff --git a/apps/docs/content/docs/(index)/prisma-orm/create-prisma.mdx b/apps/docs/content/docs/(index)/prisma-orm/create-prisma.mdx index 8c9b017c6c1..ab8a57ae088 100644 --- a/apps/docs/content/docs/(index)/prisma-orm/create-prisma.mdx +++ b/apps/docs/content/docs/(index)/prisma-orm/create-prisma.mdx @@ -107,7 +107,7 @@ npm run db:init npm run dev ``` -Sample records are seeded on the app's first query. From there, change the contract under `src/prisma/` (`packages/database/src/` in the `turborepo` template), run `npm run contract:emit`, plan the migration with `npm run migration:plan -- --name `, and apply it with `npm run migrate -- --advance-ref db`. Keep `--advance-ref db` on every apply in development: it points the `db` ref at the state you applied, and the next `migration plan` starts from there. Without it, the next plan starts from the state before your last migration and plans its changes again, and `npm run migrate` then fails with `MIGRATION.PATH_UNREACHABLE`. [Create a new app with PostgreSQL](/prisma-orm/quickstart/postgresql) covers that loop in detail, and [Create a new app with MongoDB](/prisma-orm/quickstart/mongodb) covers the MongoDB connection string. +Sample records are seeded on the app's first query. From there, change the contract under `src/prisma/` (`packages/database/src/` in the `turborepo` template), run `npm run contract:emit`, plan the migration with `npm run migration:plan -- --name `, and apply it with `npm run migrate`. Each apply points the `db` ref at the state you applied, and the next `migration plan` starts from there. [Create a new app with PostgreSQL](/prisma-orm/quickstart/postgresql) covers that loop in detail, and [Create a new app with MongoDB](/prisma-orm/quickstart/mongodb) covers the MongoDB connection string. ### Generated scripts diff --git a/apps/docs/content/docs/(index)/prisma-orm/from-scratch.mdx b/apps/docs/content/docs/(index)/prisma-orm/from-scratch.mdx index 023252ce5c7..b057aff192c 100644 --- a/apps/docs/content/docs/(index)/prisma-orm/from-scratch.mdx +++ b/apps/docs/content/docs/(index)/prisma-orm/from-scratch.mdx @@ -39,15 +39,15 @@ npm pkg set type=module Install the runtime library, the command-line tool, and the tooling to run a TypeScript file: ```npm -npm install @prisma/orm-postgres dotenv -npm install --save-dev prisma tsx typescript +npm install @prisma/orm-postgres pg dotenv +npm install --save-dev prisma tsx typescript @types/pg ``` -`@prisma/orm-postgres` is the library your code imports, and `prisma` is the command-line tool. `dotenv` loads `.env`, `tsx` runs `index.ts` without a build step, and `typescript` 5.9 or newer is a peer dependency of `@prisma/orm-postgres`. +`@prisma/orm-postgres` is the library your code imports, and `prisma` is the command-line tool. `pg` is the PostgreSQL driver, a peer dependency of `@prisma/orm-postgres`, and `@types/pg` gives TypeScript its types. `dotenv` loads `.env`, `tsx` runs `index.ts` without a build step, and `typescript` 5.9 or newer is a peer dependency of `@prisma/orm-postgres`. `temporal-polyfill` is a peer dependency of `@prisma/orm-postgres` too. It adds `Temporal`, the newer JavaScript date and time API, to runtimes such as Node.js 24 that do not have it built in. npm installs it for you, but with Yarn you add it yourself. -The two Prisma packages have different version numbers, for example `prisma` 8.0.0-rc.34 and `@prisma/orm-postgres` 8.0.0-rc.24. That is normal, and any two `latest` versions work together. +The two Prisma packages have different version numbers, for example `prisma` 8.0.0-rc.35 and `@prisma/orm-postgres` 8.0.0-rc.25. That is normal, and any two `latest` versions work together. ## 2. Create the config file and `.env` @@ -253,10 +253,10 @@ ALTER TABLE "public"."User" ADD COLUMN "phone" text; Two directories appear under `migrations/app/`: a baseline that records the table `db init` created, and your change. The baseline is never applied to this database, because the database is already signed at that state. Each migration directory holds a `migration.ts` you can read and edit; [Generating a migration](/orm/migrations/generating-a-migration) explains the files. -Apply the migration with `--advance-ref db`, which records that your development database is now at the new contract so the next `migration plan` starts from there: +Apply the migration with `db migrate`, which also records in the `db` ref that your development database is now at the new contract, so the next `migration plan` starts from there: ```npm -npx prisma db migrate --advance-ref db +npx prisma db migrate ``` ```text @@ -300,7 +300,7 @@ npx prisma migration status ✔ Up to date ``` -From here, every schema change follows the same routine: edit `prisma/contract.prisma`, run `npx prisma contract emit`, run `npx prisma migration plan --name `, and apply with `npx prisma db migrate --advance-ref db`. +From here, every schema change follows the same routine: edit `prisma/contract.prisma`, run `npx prisma contract emit`, run `npx prisma migration plan --name `, and apply with `npx prisma db migrate`. ## Next steps diff --git a/apps/docs/content/docs/(index)/prisma-orm/index.mdx b/apps/docs/content/docs/(index)/prisma-orm/index.mdx index faf8faa6145..a70c309b685 100644 --- a/apps/docs/content/docs/(index)/prisma-orm/index.mdx +++ b/apps/docs/content/docs/(index)/prisma-orm/index.mdx @@ -108,7 +108,7 @@ Check the Node.js version first: `node --version` must print 22.18 or newer on t 1. Scaffold the app: `npm create prisma@latest -- my-app --template [framework] --provider postgres --yes`. Then run `npx prisma@latest init` in the project directory so the Prisma agent skills are installed and stay current, and use them. 2. Get a database connection string: use the one I give you, or create a Prisma Postgres database: check `npx prisma auth whoami` (if I am not signed in, stop and ask me to run `npx prisma auth login`), then `npx prisma project create my-app-db` and `npx prisma postgres create mydb`, which prints the connection string once. Name that project differently from the app, so that it does not collide with the project the deploy in step 6 creates. Export the connection string as `DATABASE_URL` in the shell: in a project created with `npm create prisma`, the Prisma CLI scripts in package.json read the environment variable, not `.env`. 3. From the project directory, apply the starter contract: `npm run db:init`. The app seeds sample users on its first query, from `src/prisma/seed.ts` (`packages/database/src/seed.ts` for turborepo); there is no seed command to run. -4. Edit the starter contract under `src/prisma/` (`packages/database/src/` for turborepo) into a small schema for my use case, then run `npm run contract:emit` and plan and apply the migration: `npx prisma migration plan --name `, then `npx prisma db migrate --advance-ref db --yes`. Migration planning diffs the emitted contract, so the emit step is required. Pass `--advance-ref db` on every apply to this development database, so that the next `migration plan` starts from the state you applied; without it, the next plan repeats the last change and `db migrate` fails with `MIGRATION.PATH_UNREACHABLE`. +4. Edit the starter contract under `src/prisma/` (`packages/database/src/` for turborepo) into a small schema for my use case, then run `npm run contract:emit` and plan and apply the migration: `npx prisma migration plan --name `, then `npx prisma db migrate --yes`. Migration planning diffs the emitted contract, so the emit step is required. `db migrate` also points the `db` ref at the state you applied, so that the next `migration plan` starts from there. 5. Update `src/prisma/seed.ts` (`packages/database/src/seed.ts` for turborepo) and the app routes to query the new schema, start `npm run dev` in the background (with `DATABASE_URL` exported), and verify with a request against the running app. For the `nest` template, if routes return 500s with `reading 'findAll'` in the logs, add explicit `@Inject()` tokens as shown in https://www.prisma.io/docs/guides/frameworks/nestjs.md. 6. Deploy with Prisma Compute. The scaffold declares the app for Prisma Composer in `module.ts` and `service.ts`, with the framework's build requirements (Next.js standalone output, Astro's node adapter, SvelteKit's node adapter, TanStack Start's Nitro build) already configured; the framework guide at https://www.prisma.io/docs/guides/frameworks/[guide].md has the details, where [guide] is the template name except: template `next` → guide `nextjs`, `nest` → `nestjs`, `svelte` → `sveltekit`; `minimal` and `turborepo` have no framework guide. Check `npx prisma auth whoami`. If I am not signed in, stop and ask me to run `npx prisma auth login`, because that step opens a browser. Then run `npm run build` followed by `npx prisma deploy`, and verify the deployed URL with curl. The deployed app provisions and seeds its own Prisma Postgres database; do not pass the local DATABASE_URL. If the deploy fails with `HostedStateBootstrapError`, a project with the module's name exists in my workspace but its hosted state cannot be verified; re-run the deploy with `--name `. diff --git a/apps/docs/content/docs/(index)/prisma-orm/quickstart/existing-app/mongodb.mdx b/apps/docs/content/docs/(index)/prisma-orm/quickstart/existing-app/mongodb.mdx index 99ea60e08ed..f151e450b40 100644 --- a/apps/docs/content/docs/(index)/prisma-orm/quickstart/existing-app/mongodb.mdx +++ b/apps/docs/content/docs/(index)/prisma-orm/quickstart/existing-app/mongodb.mdx @@ -61,7 +61,7 @@ installed ├─ mongodb ├─ prisma@latest (dev) ├─ @types/node (dev) -└─ @prisma/cli-engine@0.10.0 (dev) +└─ @prisma/cli-engine@0.10.4 (dev) ✔ Done. Open prisma-8.md to get started. ``` @@ -278,7 +278,7 @@ The output continues with a preview of the MongoDB commands. The first plan in a Apply the migration: ```npm -npx prisma db migrate --advance-ref db +npx prisma db migrate ``` ```text no-copy @@ -295,9 +295,9 @@ App space ✔ Advanced ref "db" → a7d00abb0f8fc9c9f5ace78b306278673e60cc5774ec1833cd0cfd334beead54 ``` -`db migrate` runs only the migrations that the database does not have yet, so here it runs only your change. `--advance-ref db` writes the new hash to the `db` ref, so that the next `migration plan` contains only your next change. Pass it every time you apply a migration to your development database. Commit the `migrations/` directory again. +`db migrate` runs only the migrations that the database does not have yet, so here it runs only your change. It also writes the new hash to the `db` ref, so that the next `migration plan` contains only your next change. Commit the `migrations/` directory again. -To apply the migrations to any other database, such as production, pass its connection string. Leave out `--advance-ref`, because the `db` ref describes your development database: +To apply the migrations to any other database, such as production, pass its connection string. With `--db`, `db migrate` leaves the `db` ref alone, because the ref describes your development database: ```npm npx prisma db migrate --db "$PRODUCTION_DATABASE_URL" @@ -305,7 +305,7 @@ npx prisma db migrate --db "$PRODUCTION_DATABASE_URL" `db migrate` runs the migrations that this database does not have yet. An empty database has no marker, so there `db migrate` runs the baseline and then your change. -Every later change follows the same four steps, which take the place of `prisma migrate dev`: edit `src/prisma/contract.prisma`, run `npx prisma contract emit`, run `npx prisma migration plan --name `, and run `npx prisma db migrate --advance-ref db`. +Every later change follows the same four steps, which take the place of `prisma migrate dev`: edit `src/prisma/contract.prisma`, run `npx prisma contract emit`, run `npx prisma migration plan --name `, and run `npx prisma db migrate`. ## Next steps diff --git a/apps/docs/content/docs/(index)/prisma-orm/quickstart/existing-app/postgresql.mdx b/apps/docs/content/docs/(index)/prisma-orm/quickstart/existing-app/postgresql.mdx index d7797d2137d..1f95b0c4426 100644 --- a/apps/docs/content/docs/(index)/prisma-orm/quickstart/existing-app/postgresql.mdx +++ b/apps/docs/content/docs/(index)/prisma-orm/quickstart/existing-app/postgresql.mdx @@ -58,9 +58,10 @@ written installed ├─ @prisma/orm-postgres ├─ dotenv +├─ pg ├─ prisma@latest (dev) ├─ @types/node (dev) -└─ @prisma/cli-engine@0.10.0 (dev) +└─ @prisma/cli-engine@0.10.4 (dev) ✔ Done. Open prisma-8.md to get started. ``` @@ -264,7 +265,7 @@ The output continues with a preview of the SQL. The first plan in a project writ Apply the migration: ```npm -npx prisma db migrate --advance-ref db +npx prisma db migrate ``` ```text no-copy @@ -281,9 +282,9 @@ App space ✔ Advanced ref "db" → ff182ac239264ad5c8539c19c350b32d6f1e18e785875e42a0301cde744f70e3 ``` -`db migrate` runs only the migrations that the database does not have yet, so here it runs only your change. `--advance-ref db` writes the new hash to the `db` ref, so that the next `migration plan` contains only your next change. Pass it every time you apply a migration to your development database. Commit the `migrations/` directory again. +`db migrate` runs only the migrations that the database does not have yet, so here it runs only your change. It also writes the new hash to the `db` ref, so that the next `migration plan` contains only your next change. Commit the `migrations/` directory again. -To apply the migrations to any other database, such as production, pass its connection string. Leave out `--advance-ref`, because the `db` ref describes your development database: +To apply the migrations to any other database, such as production, pass its connection string. With `--db`, `db migrate` leaves the `db` ref alone, because the ref describes your development database: ```npm npx prisma db migrate --db "$PRODUCTION_DATABASE_URL" @@ -291,7 +292,7 @@ npx prisma db migrate --db "$PRODUCTION_DATABASE_URL" `db migrate` runs the migrations that this database does not have yet. An empty database has no marker, so there `db migrate` runs the baseline and then your change. -Every later change follows the same four steps, which take the place of `prisma migrate dev`: edit `src/prisma/contract.prisma`, run `npx prisma contract emit`, run `npx prisma migration plan --name `, and run `npx prisma db migrate --advance-ref db`. +Every later change follows the same four steps, which take the place of `prisma migrate dev`: edit `src/prisma/contract.prisma`, run `npx prisma contract emit`, run `npx prisma migration plan --name `, and run `npx prisma db migrate`. ## Next steps diff --git a/apps/docs/content/docs/(index)/prisma-orm/quickstart/mongodb.mdx b/apps/docs/content/docs/(index)/prisma-orm/quickstart/mongodb.mdx index f637d8c4d24..d7d7ed013ce 100644 --- a/apps/docs/content/docs/(index)/prisma-orm/quickstart/mongodb.mdx +++ b/apps/docs/content/docs/(index)/prisma-orm/quickstart/mongodb.mdx @@ -66,10 +66,10 @@ The output reports the planned operations. With a PSL contract, it plans 3: it c Apply the planned migration to MongoDB: ```npm -npm run migrate -- --advance-ref db +npm run migrate ``` -`--advance-ref db` writes `migrations/app/refs/db.json`, the `db` ref, which records the contract state your development database is now at. Your next `migration plan` starts from it. Without it, the next `npm run migration:plan` stops with `MIGRATION.PLAN_ORIGIN_UNKNOWN`, because migrations exist but nothing says which one your database has. +`db migrate` also writes `migrations/app/refs/db.json`, the `db` ref, which records the contract state your development database is now at. Your next `migration plan` starts from it. The output includes `Applied 1 migration(s) (3 operation(s)) across 1 contract space(s)`, or `(2 operation(s))` with the TypeScript starter, and a line starting `Advanced ref "db"`. If it fails with a connection error, confirm `DATABASE_URL` is exported in this shell and points at a running MongoDB server. @@ -87,6 +87,6 @@ Use the URL or terminal output shown by your template. You should see the seeded ## Next steps -- Open `src/prisma/contract.prisma` or `src/prisma/contract.ts` and change the starter model. In the `turborepo` template, the contract is in `packages/database/src/` instead. Then run `npm run contract:emit`, `npm run migration:plan -- --name `, and `npm run migrate -- --advance-ref db`. Without `contract:emit`, `migration plan` reads the contract from before your change and reports `No changes detected`. +- Open `src/prisma/contract.prisma` or `src/prisma/contract.ts` and change the starter model. In the `turborepo` template, the contract is in `packages/database/src/` instead. Then run `npm run contract:emit`, `npm run migration:plan -- --name `, and `npm run migrate`. Without `contract:emit`, `migration plan` reads the contract from before your change and reports `No changes detected`. - If you already have an app, follow [Add Prisma ORM and MongoDB to an existing app](/prisma-orm/quickstart/existing-app/mongodb) when its database is empty, or [Add Prisma ORM to an existing MongoDB database](/prisma-orm/add-to-existing-project/mongodb) when the database already has collections. - Read the [Prisma ORM overview](/orm) when you want the concepts behind contracts, query APIs, and migrations. diff --git a/apps/docs/content/docs/(index)/prisma-orm/quickstart/postgresql.mdx b/apps/docs/content/docs/(index)/prisma-orm/quickstart/postgresql.mdx index ed0d7638bc3..829bb6e0ad7 100644 --- a/apps/docs/content/docs/(index)/prisma-orm/quickstart/postgresql.mdx +++ b/apps/docs/content/docs/(index)/prisma-orm/quickstart/postgresql.mdx @@ -103,6 +103,6 @@ Open the URL the command prints. You should see the seeded users returned from P ## Next steps -- Open `src/prisma/contract.prisma` or `src/prisma/contract.ts` and change the starter model. In the `turborepo` template, the contract is in `packages/database/src/` instead. Then run `npm run contract:emit`, `npm run migration:plan -- --name `, and `npm run migrate -- --advance-ref db`. Without `contract:emit`, `migration plan` reads the contract from before your change and reports `No changes detected`. Keep `--advance-ref db` on every apply to your development database: without it, the next plan repeats your last change and `npm run migrate` fails with `MIGRATION.PATH_UNREACHABLE`. +- Open `src/prisma/contract.prisma` or `src/prisma/contract.ts` and change the starter model. In the `turborepo` template, the contract is in `packages/database/src/` instead. Then run `npm run contract:emit`, `npm run migration:plan -- --name `, and `npm run migrate`. Without `contract:emit`, `migration plan` reads the contract from before your change and reports `No changes detected`. - If you already have an app, follow [Add Prisma ORM and PostgreSQL to an existing app](/prisma-orm/quickstart/existing-app/postgresql) when its database is empty, or [Add Prisma ORM to an existing PostgreSQL database](/prisma-orm/add-to-existing-project/postgresql) when the database already has tables. - Read the [Prisma ORM overview](/orm) when you want the concepts behind contracts, query APIs, and migrations. diff --git a/apps/docs/content/docs/cli/configuration.mdx b/apps/docs/content/docs/cli/configuration.mdx index 20c6a3281b7..c17a52d6776 100644 --- a/apps/docs/content/docs/cli/configuration.mdx +++ b/apps/docs/content/docs/cli/configuration.mdx @@ -278,7 +278,7 @@ export default definePrismaConfig({ Set `newline` when anyone works on the project from Windows; `"LF"` is the usual choice. Without it, on Windows `contract format` writes `CRLF` but the [Prisma editor extension](/orm/contract-authoring/editor-support) writes `LF`. Each one rewrites every line the other wrote, so Git shows the whole file as changed. The editor extension reads `formatter` from `prisma.config.ts` too, so once `newline` is set, the command and the editor write the same line endings on every machine. -`formatter` needs `@prisma/orm-postgres` or `@prisma/orm-mongo` at `8.0.0-rc.24` or later. An earlier release ignores the setting without an error, and `contract format` still indents with two spaces. `npm ls @prisma/orm-postgres`, or the same command with `@prisma/orm-mongo`, prints the release you have. +`@prisma/orm-postgres` and `@prisma/orm-mongo` read `formatter` since `8.0.0-rc.24`. An earlier release ignores the setting without an error, and `contract format` still indents with two spaces. `npm ls @prisma/orm-postgres`, or the same command with `@prisma/orm-mongo`, prints the release you have. If `indent` or `newline` has a value the table does not allow, every command that reads the config fails with the error code `CLI.CONFIG_SECTION_INVALID`, which says the `orm` section is invalid. A second message under it, with the code `CLI.CONFIG_FIELD_INVALID`, names the field, as in `formatter.indent must be at least 1 (was 0)`. With `--json`, the first code is in `envelope.error.code` and the second is an entry in `envelope.diagnostics`. diff --git a/apps/docs/content/docs/cli/contract-infer.mdx b/apps/docs/content/docs/cli/contract-infer.mdx index 9c8f18c701f..66a781b8987 100644 --- a/apps/docs/content/docs/cli/contract-infer.mdx +++ b/apps/docs/content/docs/cli/contract-infer.mdx @@ -62,7 +62,7 @@ In a list column's type, a `?` means something different depending on where it i A list column that Prisma ORM migrations created cannot hold `NULL` elements, because the migration adds a check that stops it, so it gets no `?` before the brackets. Any other list column gets one. -Each column gets a type such as `String(storage: varchar, length: 20)`, `Int(storage: int2)`, `Bit(8)`, `Varbit(16)`, `Xml`, `Money`, or `Duration(precision: 3)`, written with the fewest parameters that describe the column exactly. Where a [convenience type](/orm/contract-authoring/psl-syntax#models-and-fields) gives the column's type, the contract writes it with only the arguments that differ from its defaults. The types come from Prisma ORM's types for your database and from the extension packs listed under `extensions` in `prisma.config.ts`. An extension pack is the Prisma ORM package for a database extension, such as pgvector. +Each column gets a type such as `String(storage: varchar, length: 20)`, `Int(storage: int2)`, `Json(storage: jsonb)`, `Bit(8)`, `Varbit(16)`, `Xml`, `Money`, or `Duration(precision: 3)`, written with the fewest parameters that describe the column exactly. Where a [convenience type](/orm/contract-authoring/psl-syntax#models-and-fields) gives the column's type, the contract writes it with only the arguments that differ from its defaults. The types come from Prisma ORM's types for your database and from the extension packs listed under `extensions` in `prisma.config.ts`. An extension pack is the Prisma ORM package for a database extension, such as pgvector. When a column has a type that none of these provide, the command writes no file. It fails with `CONTRACT.INFER_COLUMN_TYPE_UNCLAIMED` and lists every such column, such as `public.doc.meta: hstore`. To get past the error, do one of the following for each listed column: diff --git a/apps/docs/content/docs/cli/db-migrate.mdx b/apps/docs/content/docs/cli/db-migrate.mdx index a16b14917fd..e74a848bafb 100644 --- a/apps/docs/content/docs/cli/db-migrate.mdx +++ b/apps/docs/content/docs/cli/db-migrate.mdx @@ -8,9 +8,13 @@ metaDescription: Learn how to apply pending Prisma ORM on-disk migrations with t `db migrate` applies the migrations on disk that the database has not run yet, including the ones that extension packages ship. It runs the extensions' migrations first, in alphabetical order of extension, and then yours. It never writes a new migration; [`migration plan`](/cli/migration-plan) does that. +A database can record [policies](/orm/migrations/database-policies) that limit how it changes, and `db migrate` obeys them. When the database's change policy does not include `migrate`, the command refuses to run. When its data protection policy forbids an operation in one of the pending migrations, the command refuses the whole run before it applies anything. + Prisma ORM keeps one migration history for your own models, called the `app` space, in `migrations/app/`, and one for each [extension package](/orm/extensions/using-extensions) that ships its own migrations, such as pgvector. Each of these histories is a [contract space](/orm/migrations/the-migration-graph#terms-used-on-this-page). -In development, run `npx prisma db migrate --advance-ref db`, so that your next `migration plan` starts from what you just applied. In CI and production, it replaces Prisma ORM 7's `migrate deploy`: run it from your deployment pipeline, without `--advance-ref`, after the migrations have been reviewed. Plain `db migrate` applies migrations until the database matches `contract.json`. If you name the state each environment should reach with a ref, such as `prod`, run `db migrate --to prod` instead, as [Applying to a target](#applying-to-a-target) shows. +In development, when you run `npx prisma db migrate`, the command applies your migrations and then points the `db` [ref](/cli/migration-ref) at the contract your database is now at, so your next `migration plan` starts from what you just applied. [The `db` ref](#the-db-ref) lists when it does this. This is the behavior since `8.0.0-rc.25`; before that release, you passed `--advance-ref db` to get it. + +In CI and production, `db migrate` replaces Prisma ORM 7's `migrate deploy`. Run it from your deployment pipeline after the migrations have been reviewed, and pass `--db` or `--no-advance-ref` so that the run changes no file in your repository. Plain `db migrate` applies migrations until the database matches `contract.json`. If you name the state each environment should reach with a ref, such as `prod`, run `db migrate --to prod` instead, as [Applying to a target](#applying-to-a-target) shows. ## Usage @@ -24,12 +28,37 @@ npx prisma db migrate --db "$DATABASE_URL" | --- | --- | | `--db ` | Connects to the database. | | `--to ` | Applies migrations up to a target contract state. Accepts a [contract reference](/cli/migration-ref#contract-reference-forms): a hash, a hash prefix, a [ref name](#contract-references), a migration directory name, [`^`](#contract-references), [`@contract`](#contract-references), [`@db`](#contract-references), or [`@empty`](#contract-references). | -| `--advance-ref ` | After a successful run, points the named [ref](/cli/migration-ref) at the contract state the database now matches. Pass `--advance-ref db` in development. | +| `--advance-ref ` | After a successful run, points the named [ref](/cli/migration-ref) at the contract state the database now matches. Works with `--db` and in CI too. See [The `db` ref](#the-db-ref). | +| `--no-advance-ref` | Changes no ref. Added in `8.0.0-rc.25`. Cannot be combined with `--advance-ref`. | | `--show` | Prints the migrations `db migrate` would run, and runs nothing. | +| `--permit-policy-change` | With `--to `, checks the run against the ref's declared [policies](/orm/migrations/database-policies) and writes them into the database when it succeeds. Without it, a ref whose policies differ from the database's fails with `MIGRATION.POLICY_MISMATCH`. Pass it only when the owner of the database means to apply the ref's policies. | | `--from ` | Use it with `--show`, where it sets the starting state for the preview. Accepts a [contract reference](/cli/migration-ref#contract-reference-forms): a hash, a hash prefix, a [ref name](#contract-references), a migration directory name, [`^`](#contract-references), [`@contract`](#contract-references), [`@db`](#contract-references), or [`@empty`](#contract-references). | | `--config ` | Read this config file instead of `./prisma.config.ts`. | | `--json` | Prints a machine-readable result. | +### The `db` ref [#the-db-ref] + +The `db` ref is the file `migrations/app/refs/db.json`. It records which contract your development database is at, and `migration plan` starts from it when you do not pass `--from`. Commit it with your migrations, as you do every [ref file](/cli/migration-ref). When two branches both change it, git reports a conflict in the file: take either side, then run `db migrate`, which points the ref at your own database again, as [Merge both branches](/guides/database/schema-changes#33-merge-both-branches) shows. + +When you run `db migrate` with the connection from `prisma.config.ts`, and the command does not detect CI, it points the `db` ref at the contract the database is at after the run, as [`db init`](/cli/db-init) and [`db update`](/cli/db-update) do. In every other situation it leaves the `db` ref alone unless you pass `--advance-ref`: + +| Situation | Ref that `db migrate` updates | +| --- | --- | +| Connection from `prisma.config.ts`, CI not detected | `db` | +| Connection from `prisma.config.ts`, CI detected | None. The command prints the notice `MIGRATION.REF_NOT_ADVANCED_IN_CI` | +| `--db ` | None | +| `--advance-ref ` | `` | +| `--no-advance-ref` | None | +| The run ends at the empty contract, such as `--to @empty`, with the connection from `prisma.config.ts`, and without `--advance-ref` or `--no-advance-ref` | None. An existing `db` ref stays as it is, with the warning `MIGRATION.REF_NOT_ADVANCED_TO_EMPTY` | + +A ref cannot name the empty contract, so a run that ends there with `--advance-ref ` is refused with `MIGRATION.REF_TARGET_EMPTY` before it applies anything. Passing `--advance-ref` and `--no-advance-ref` together fails with `CLI.ADVANCE_REF_ARG_CONFLICT`. + +The command detects CI when the `CI` environment variable is set, or when a variable that CI services set is present, such as `GITHUB_ACTIONS` or `BUILD_NUMBER`. Set `CI=false` to turn the detection off. + +A deploy that is not a CI job, such as a container's start command or a release command, still reads its connection from `prisma.config.ts`, so a plain `db migrate` there would rewrite `migrations/app/refs/db.json`. Pass `--no-advance-ref`, or the connection string with `--db`, in those commands. + +If the ref file cannot be written, for example on a read-only filesystem, the command prints the warning `MIGRATION.REF_NOT_WRITTEN` and still exits `0`, because the migrations have been applied. + ### Contract references [#contract-references] A ref name is a name you gave a contract state with [`migration ref set`](/cli/migration-ref), such as `prod`. `^` is a migration directory name followed by `^`, and it names the contract state before that migration, while the directory name alone names the state after it. [Contract references each command accepts](/cli/migration-ref#contract-reference-forms) lists the forms for every command. @@ -55,7 +84,7 @@ npx prisma db verify --db "$DATABASE_URL" ```npm npx prisma db migrate --show -npx prisma db migrate --show --from @contract --to production +npx prisma db migrate --show --from @contract --to prod ``` A `--from` that is not `@db` sets the starting state of your own migrations only. The preview starts every extension's migrations from an empty database, so it can list extension migrations your database has already run. To see exactly what a run against a database would do, preview without `--from`. @@ -65,7 +94,7 @@ A `--from` that is not `@db` sets the starting state of your own migrations only If your project uses named [refs](/cli/migration-ref), apply up to a target ref: ```npm -npx prisma db migrate --db "$DATABASE_URL" --to production +npx prisma db migrate --db "$DATABASE_URL" --to prod ``` Manage refs with [`migration ref`](/cli/migration-ref). @@ -84,27 +113,27 @@ You edited the contract, ran `contract emit`, and then ran `db migrate`. The tar ```text ✘ [MIGRATION.PATH_UNREACHABLE] Current contract has no planned migration path - why: No migration edge connects the current state "" to the target "" in contract space "app". -→ Plan the missing edge: prisma migration plan --from --to --name -→ Apply it: prisma db migrate --to + why: No migration edge connects "" to the target "" in contract space "app". The on-disk migration graph does not join the two, and migrate replays existing edges — it never invents one. +→ Plan the missing edge: prisma migration plan --from +→ Apply it: prisma db migrate ``` -Do not run the commands as the error prints them. Its [`migration plan`](/cli/migration-plan) command fails with `MIGRATION.REF_NOT_FOUND`, because `--to` only accepts a contract that a migration already produces, and its `db migrate --to` command fails with `MIGRATION.PATH_UNREACHABLE` again until the migration is planned. Run `migration plan` without `--to`, with the current hash from the error and a name for the migration, then apply the result. The first seven characters of the hash are enough: +Run the two commands the error prints, with `npx` in front of each. If you passed `--db`, the second one ends with `--db `: put your connection string in place of ``. The first, [`migration plan`](/cli/migration-plan), writes the missing migration, and the second applies it. Add `--name` to the first command to name the new migration's directory, whose name otherwise ends in `_migration`: ```npm npx prisma migration plan --from --name add-phone -npx prisma db migrate --db "$DATABASE_URL" +npx prisma db migrate ``` -Without `--to`, `migration plan` plans up to the contract you just emitted. +The printed `migration plan` has no `--to`, because without one it plans up to the contract you just emitted. ### You passed `--to` with an earlier migration -`db migrate` cannot run a migration backwards. To take the database back, you plan a new migration that undoes the later ones. The error is the same as above. Here the two commands it suggests work as printed, because a migration already produces each of the two states. Put `npx` in front of each: +`db migrate` cannot run a migration backwards. To take the database back, you plan a new migration that undoes the later ones. The error is the same as above, and its two commands also run as printed, with the earlier state as their `--to`. Put `npx` in front of each, and as before, the second ends with `--db ` only if you passed `--db`: ```npm npx prisma migration plan --from --to --name undo-phone -npx prisma db migrate --to --db "$DATABASE_URL" +npx prisma db migrate --to ``` The new migration usually drops columns or tables, and the data in them. `migration plan` asks you to confirm each drop. In a script it stops instead, and names the flag to pass to `migration plan`, such as `--delete User.phone`. It writes the migration to a new directory under `migrations/app/`, so read the `migration.ts` there before you apply it. diff --git a/apps/docs/content/docs/cli/db-update.mdx b/apps/docs/content/docs/cli/db-update.mdx index f8c1fd68894..4c6224aeac0 100644 --- a/apps/docs/content/docs/cli/db-update.mdx +++ b/apps/docs/content/docs/cli/db-update.mdx @@ -10,6 +10,8 @@ metaDescription: Learn how to reconcile a database with the current Prisma ORM c Like Prisma ORM 7's `db push`, use it when you want a database to match your contract and do not need a migration file for the change, for example on your development database while you try out a contract change. +A database whose [change policy](/orm/migrations/database-policies) does not include `reconcile` refuses `db update` with `MIGRATION.CHANGE_POLICY_FORBIDS`. Its [data protection policy](/orm/migrations/database-policies#data-protection-policy) decides whether the update asks before it loses data or changes access, refuses, or goes ahead without asking. A database that records no policy allows `db update`, which then asks before it loses data or changes access. + ## Usage ```npm @@ -23,10 +25,11 @@ npx prisma db update --db "$DATABASE_URL" | `--db ` | Connects to the database. | | `--dry-run` | Shows planned operations without applying them. | | `--to ` | Updates to a specific contract state. Accepts a [contract reference](/cli/migration-ref#contract-reference-forms): a hash, a hash prefix, a [ref name](#contract-references), a migration directory name, or [`^`](#contract-references). It refuses `@contract`, `@db`, and `@empty` with the error code `MIGRATION.REF_WRONG_GRAMMAR`. To update to the contract in `contract.json`, leave out `--to`. | -| `--rename :` | Renames a namespace, a model or a field and keeps its rows, instead of dropping and creating it, or moves a model to another namespace. On PostgreSQL and SQLite, also renames an enum value in the rows that hold it, as in `--rename Status.ARCHIVED:Status.RETIRED`, a field of a value object, as in `--rename GeoPoint.lat:GeoPoint.latitude`, and a variant. Repeatable. See [Renames and data loss](#renames-and-data-loss). | -| `--delete ` | Lets the update lose the data of a model, a field, a table no model stores, every model of a namespace the contract removed, or, on PostgreSQL and SQLite, an enum value the contract removed, a field of a value object, or the rows of a variant. Repeatable. | -| `--convert ` | On PostgreSQL and SQLite, rewrites the stored discriminator value of a variant whose value changed. Repeatable. | +| `--rename :` | Renames a namespace, a model or a field and keeps its rows, instead of dropping and creating it, or moves a model to another namespace. On PostgreSQL, SQLite and MongoDB, also renames an enum value in the rows that hold it, as in `--rename Status.ARCHIVED:Status.RETIRED`, a field of a value object, as in `--rename GeoPoint.lat:GeoPoint.latitude`, and a variant. Repeatable. See [Renames and data loss](#renames-and-data-loss). | +| `--delete ` | Lets the update lose the data of a model, a field, a table no model stores, every model of a namespace the contract removed, or, on PostgreSQL, SQLite and MongoDB, an enum value the contract removed, a field of a value object, or the rows or documents of a variant. Repeatable. | +| `--convert ` | On PostgreSQL, SQLite and MongoDB, rewrites the stored discriminator value of a variant whose value changed. Repeatable. | | `--allow ` | Lets one operation change who can read or write the model's data. Repeatable. | +| `--permit-policy-change` | With `--to `, checks the run against the ref's declared [policies](/orm/migrations/database-policies) and writes them into the database when it succeeds. Without it, a ref whose policies differ from the database's fails with `MIGRATION.POLICY_MISMATCH`. Pass it only when the owner of the database means to apply the ref's policies. | | `--advance-ref ` | After the update, points the named [ref](/cli/migration-ref) at the contract state the database now matches. Without it, `db update` points the `db` ref there when you leave out `--db`, and changes no ref when you pass `--db`. | | `--config ` | Read this config file instead of `./prisma.config.ts`. | | `--json` | Prints a machine-readable result. | @@ -60,6 +63,34 @@ In a terminal, the command asks the questions you did not answer with a flag. In Dropping an index, a unique or foreign-key constraint, a check, a default or a native enum type loses no data, so the update asks nothing about it. +### A changed stored name [#a-changed-stored-name] + +On PostgreSQL and SQLite, a model, field or enum member keeps its identity as long as it keeps its name in the contract, even when the name it is stored under changes. So when you change only a model's `@@map`, a field's `@map`, or the value an enum member stores, the update keeps the data and asks nothing: + +```prisma title="contract.prisma" +model User { + id Int @id + email String @map("email_address") // was @map("email") + @@map("accounts") // was @@map("users") +} +``` + +The update renames the table `users` to `accounts` and the column `email` to `email_address`, together with the constraints and indexes named after them. For an enum member that keeps its name but stores a new value, the update replaces the old value in the rows. A table or column is renamed only when its [control policy](/orm/contract-authoring/psl-syntax#control-policy) is `managed` in both contracts. + +Because nothing is asked, a `--delete` for such a change fails with `CLI.CONSENT_UNUSED`. If you want an empty table under the new name instead, make two changes, each applied before the next: remove the model and answer `--delete`, then add it back with its new `@@map`. + +Some changes cannot be made in one step, and are refused with `MIGRATION.PLANNING_FAILED`: + +- two models or fields that trade tables or columns; +- a model or field that moves to a name another one gives up in the same change; +- a model or field that takes over the table or column of one the change removes; +- enum members that trade stored values; +- an enum member that takes the stored value of a member the change removes. + +Make each of these changes in two steps, applied one after the other. For a trade, or a name another one gives up, go through a name nothing uses, such as `prisma_swap_users`. For a takeover, first remove the model, field or enum member that holds the name, then add the new one in the second step. If that first step removes an enum member and you answer `--delete`, a required column cannot keep the rows that hold the member: delete those rows, or set them to a value the enum keeps, before the step is applied. + +On MySQL and MongoDB, a changed stored name is handled as it was on every database before `8.0.0-rc.25`: a changed `@@map` is planned as dropping the table and creating an empty one, and asks for `--delete`. + `db update` names each subject by model and field from the contract the database was last updated to, which it stores when it advances a ref. With `--db`, pass `--advance-ref ` on every run so that contract is stored for the next run. Without a stored contract, each subject is its storage name, and a run with `--rename` fails with `MIGRATION.STATEMENT_ORIGIN_UNKNOWN`. Adding `--advance-ref` to that run does not help, because the missing contract is the one the database is at before it. To store it, emit the contract the database is at, run `db update --advance-ref db --dry-run` with the same `--db`, and check that it plans no operations. Then run it again without `--dry-run`, which changes nothing in the database and stores the contract. Then emit the new contract and run the rename. On PostgreSQL, a namespace is renamed, moved or removed with the same flags. `--rename billing:finance` renames the schema, and everything in it stays in it. `--rename public.Invoice:billing.Invoice` moves the model's table to another schema with its rows, constraints, indexes and policies, and creates the schema first when the database does not have it. Namespace renames run before the other renames, whatever order you give them in. `public` and a schema another contract space declares are not renamed. @@ -74,12 +105,12 @@ The schema can also hold objects that no contract declares. A table created by h The command leaves alone a schema that no contract declared, such as Supabase's `auth`, and a namespace that only another contract space declares. Before `8.0.0-rc.20`, the command did not ask about a removed namespace and left its tables in place. -On PostgreSQL and SQLite, removing a member from an `enum` block, or changing the value a member stores, is asked about too, because rows may hold the old value. The update asks once for each value, however many columns hold it: +On PostgreSQL and SQLite, removing a member from an `enum` block is asked about too, because rows may hold its value. The update asks once for each value, however many columns hold it: - If you renamed the member, answer with `--rename Status.ARCHIVED:Status.RETIRED`. The update changes the stored value in every column and list that holds it. - To let the value go, answer with `--delete Status.ARCHIVED`. Optional columns that hold it are set to `NULL`, and lists lose it. A required column cannot take `NULL`, so while any of its rows hold the value, the apply fails with `MIGRATION.PRECHECK_FAILED` before it changes anything. The error counts those rows and says how to keep them. -A member you rename while keeping its stored value, such as `RETIRED = "archived"` in place of `ARCHIVED = "archived"`, changes no rows, so nothing is asked. A member that keeps its name but stores a new value, and two members that swap their stored values, can only be answered with `--delete`. `db update` cannot keep those rows in one run. Its question says to plan the change with [`migration plan --from `](/cli/migration-plan#renames-and-data-loss) instead, or, for a member that keeps its name, to rename it to a new member and back in two runs of `db update`. For a swap, only the migration works. +A member you rename while keeping its stored value, such as `RETIRED = "archived"` in place of `ARCHIVED = "archived"`, changes no rows, so nothing is asked. A member that keeps its name but stores a new value is [a changed stored name](#a-changed-stored-name): the update replaces the value in the rows and asks nothing. Two members that swap their stored values are refused; make the swap in two runs through a value nothing uses. A member that takes the stored value of a member you remove is refused too; remove the old member in one run and add the new one in the next. Native PostgreSQL enums (`pg.enum(...)`) are not affected. Before `8.0.0-rc.21`, PostgreSQL failed at apply when a row held the removed value, and SQLite planned nothing. @@ -96,7 +127,7 @@ A [variant](/orm/contract-authoring/psl-syntax#base-models-and-variants) whose d - `--rename Bug:Defect` of a variant whose value also changed rewrites the value in the same way. - `--delete Bug` deletes the rows that hold the old value, then drops a removed variant's own table or the columns only it used. -On MongoDB, `--rename` of a value object field or of a variant whose discriminator value changes is refused, and so is `--convert` of a variant. +On MongoDB, changes inside documents are asked about too, since `8.0.0-rc.25`: a field a value object or an embedded model loses, a stored value an enum loses, and a variant that is removed or whose discriminator value changes. They take the same answers as in [`migration plan`](/cli/migration-plan#renames-and-data-loss). With `--no-interactive` and no answers, the update fails with `CLI.CONSENT_REQUIRED` and lists the flags to add. On MongoDB, a field type change that can lose values is asked about, as on SQL. Answer with `--delete` and the field, as in `--delete User.age`, which keeps the field and casts its stored values with `$convert`. To write the conversion yourself, use `migration plan --convert` instead, because `db update` writes no migration for you to edit. diff --git a/apps/docs/content/docs/cli/index.mdx b/apps/docs/content/docs/cli/index.mdx index 9e8d4f1f516..bfa385c6acf 100644 --- a/apps/docs/content/docs/cli/index.mdx +++ b/apps/docs/content/docs/cli/index.mdx @@ -102,7 +102,15 @@ npx prisma db migrate --db "$DATABASE_URL" --advance-ref db npx prisma db verify --db "$DATABASE_URL" ``` -`db migrate` changes no ref unless you pass `--advance-ref db`. Pass it in development, so that the next `migration plan` starts from what you just applied instead of planning the same change again. Leave it off in CI and deployments, which should not change the refs in your repository: there, run `npx prisma db migrate`, or `npx prisma db migrate --to ` if you name the state each environment should reach with a ref. +When `db migrate` takes its connection from `prisma.config.ts` and does not detect CI, it updates the `db` ref, so the next `migration plan` starts from what you just applied. With `--db`, as above, or in CI, it changes no ref unless you pass `--advance-ref db`. + +A deployment should not change the refs in your repository. If it reads its connection from `prisma.config.ts` and does not run as a CI job, pass `--no-advance-ref`: + +```npm +npx prisma db migrate --no-advance-ref +``` + +If you keep a ref for each environment, such as `prod`, run `npx prisma db migrate --to --no-advance-ref` instead. ## Agent skills diff --git a/apps/docs/content/docs/cli/migration-plan.mdx b/apps/docs/content/docs/cli/migration-plan.mdx index 3322f395d04..2cee7644e48 100644 --- a/apps/docs/content/docs/cli/migration-plan.mdx +++ b/apps/docs/content/docs/cli/migration-plan.mdx @@ -15,7 +15,11 @@ With neither, what happens depends on the migrations already on disk: - **`migrations/app/` is empty.** The plan starts from an empty database and contains the full `CREATE` operations for the whole contract. This is the first migration in a new project. The command says so under its summary (`No db ref set — planning from an empty database`), and `--json` output carries `fromDefaulted: true`, so a plan that recreates a database you already have is easy to spot. If a database already exists, run `db init`, `db update`, or `db sign` first. - **Migrations already exist.** The command refuses with `MIGRATION.PLAN_ORIGIN_UNKNOWN` rather than write a migration that creates every table from nothing, which no existing database could apply. The error names three ways out: `migration ref set db ` to point the ref at the state your database is at, `--from ` to name the starting state for this one plan, or `--from @empty` when you do mean to plan from an empty database. To find the state your database is at, run `npx prisma migration status`, which prints its hash next to the `@db` label, and pass that hash, or the directory name of the migration that ends at it, as ``. -Keep the `db` ref current and you never see the refusal. [`db init`](/cli/db-init) and [`db update`](/cli/db-update) update it for you when you run them without `--db`; with `--db` you have to add `--advance-ref db`. [`db sign`](/cli/db-sign) updates it whenever it signs, `--db` or not, unless you pass `--no-advance-ref`. [`db migrate`](/cli/db-migrate) updates no ref unless you pass `--advance-ref db`. +Keep the `db` ref current and you never see the refusal. When you work against your development database with the connection from `prisma.config.ts`, the commands that change it keep the ref current for you. The exceptions are listed per command: + +- [`db init`](/cli/db-init) and [`db update`](/cli/db-update) update it unless you pass `--db`. With `--db`, add `--advance-ref db`. +- [`db sign`](/cli/db-sign) updates it every time it signs, with or without `--db`, unless you pass `--no-advance-ref`. +- [`db migrate`](/cli/db-migrate) updates it unless you pass `--db` or it runs in CI. Add `--advance-ref db` to update it there too. ### The automatic baseline @@ -25,7 +29,7 @@ Say `migrations/app/` has no migrations yet, the `db` ref is set, and `migration The baseline only creates things, because it is planned from an empty database, so it never removes data. The second migration can remove data, and `migration plan` asks about it before it writes either one, as [Renames and data loss](#renames-and-data-loss) describes. -If a migration already starts from the contract the `db` ref points at, `migration plan` writes a second migration that starts from the same contract, so the [migration history](/orm/migrations/the-migration-graph) splits into two branches. This happens, for example, after `db migrate` without `--advance-ref db`, which applies migrations but leaves the `db` ref where it was. `migration plan` still writes the migration and prints a warning. A database that has already run the existing migration then has no migration leading to your new contract, so `db migrate` on that database fails with `MIGRATION.PATH_UNREACHABLE`. To build on what that database has applied instead, delete the directory this run wrote and plan again with `--from` set to the state the database is at. `npx prisma migration status` prints that state's hash next to the `@db` label. +If a migration already starts from the contract the `db` ref points at, `migration plan` writes a second migration that starts from the same contract, so the [migration history](/orm/migrations/the-migration-graph) splits into two branches. This happens, for example, after `db migrate --db ` or `db migrate` in CI, which apply migrations but leave the `db` ref where it was. `migration plan` still writes the migration and prints a warning. A database that has already run the existing migration then has no migration leading to your new contract, so `db migrate` on that database fails with `MIGRATION.PATH_UNREACHABLE`. To build on what that database has applied instead, delete the directory this run wrote and plan again with `--from` set to the state the database is at. `npx prisma migration status` prints that state's hash next to the `@db` label. The command is offline, so it does not need a database connection. @@ -42,10 +46,10 @@ npx prisma migration plan --name add_users_table | `--name ` | Sets the migration directory name suffix. | | `--from ` | Uses a specific starting contract state instead of the `db` ref. Accepts a [contract reference](/cli/migration-ref#contract-reference-forms): a hash, a hash prefix, a [ref name](#contract-references), a migration directory name, [`^`](#contract-references), or [`@empty`](#contract-references). `@db` is not accepted here, because `migration plan` is offline and cannot read a database. `@contract` is not accepted either. | | `--to ` | Sets the destination contract state. Defaults to the emitted contract. Accepts the same forms as `--from`, except `@empty`, which is refused as a destination. | -| `--rename :` | Renames a namespace, a model or a field and keeps its rows, instead of dropping and creating it, or moves a model to another namespace. On PostgreSQL and SQLite, also renames an enum value in the rows that hold it, as in `--rename Status.ARCHIVED:Status.RETIRED`, a field of a value object, as in `--rename GeoPoint.lat:GeoPoint.latitude`, and a variant. Repeatable. See [Renames and data loss](#renames-and-data-loss). | -| `--delete ` | Lets the migration lose the data of a model, a field, a table no model stores, every model of a namespace the contract removed, or, on PostgreSQL and SQLite, an enum value the contract removed, a field of a value object, or the rows of a variant. For a type change, accepts the database's own cast. Repeatable. | -| `--convert ` | For a type change that can lose values, writes an `alterColumnType` whose conversion you fill in. On PostgreSQL and SQLite, `--convert ` rewrites the stored discriminator value of a variant whose value changed. Repeatable. See [Type changes and required fields](#type-changes-and-required-fields). | -| `--backfill ` | For a new required field or a field made required, writes a backfill step you fill in, instead of a temporary value. On PostgreSQL and SQLite, also takes a field of a value object, as in `--backfill GeoPoint.country`. Repeatable. See [Type changes and required fields](#type-changes-and-required-fields). | +| `--rename :` | Renames a namespace, a model or a field and keeps its rows, instead of dropping and creating it, or moves a model to another namespace. On PostgreSQL, SQLite and MongoDB, also renames an enum value in the rows that hold it, as in `--rename Status.ARCHIVED:Status.RETIRED`, a field of a value object, as in `--rename GeoPoint.lat:GeoPoint.latitude`, and a variant. Repeatable. See [Renames and data loss](#renames-and-data-loss). | +| `--delete ` | Lets the migration lose the data of a model, a field, a table no model stores, every model of a namespace the contract removed, or, on PostgreSQL, SQLite and MongoDB, an enum value the contract removed, a field of a value object, or the rows or documents of a variant. For a type change, accepts the database's own cast. Repeatable. | +| `--convert ` | For a type change that can lose values, writes an `alterColumnType` whose conversion you fill in. On PostgreSQL, SQLite and MongoDB, `--convert ` rewrites the stored discriminator value of a variant whose value changed. Repeatable. See [Type changes and required fields](#type-changes-and-required-fields). | +| `--backfill ` | For a new required field or a field made required, writes a backfill step you fill in, instead of a temporary value. On PostgreSQL, SQLite and MongoDB, also takes a field of a value object, as in `--backfill GeoPoint.country`, and on MongoDB a field of an embedded model. Repeatable. See [Type changes and required fields](#type-changes-and-required-fields). | | `--config ` | Read this config file instead of `./prisma.config.ts`. | | `--json` | Prints a machine-readable result. | @@ -69,6 +73,34 @@ In a terminal, the command asks the questions you did not answer with a flag. Wi Dropping an index, a unique or foreign-key constraint, a check, a default or a native enum type, and setting `NOT NULL`, lose no data, so the command asks nothing about them. +### A changed stored name [#a-changed-stored-name] + +On PostgreSQL and SQLite, a model, field or enum member keeps its identity as long as it keeps its name in the contract, even when the name it is stored under changes. So when you change only a model's `@@map`, a field's `@map`, or the value an enum member stores, the migration keeps the data and asks nothing: + +```prisma title="contract.prisma" +model User { + id Int @id + email String @map("email_address") // was @map("email") + @@map("accounts") // was @@map("users") +} +``` + +The migration renames the table `users` to `accounts` and the column `email` to `email_address`, together with the constraints and indexes named after them. For an enum member that keeps its name but stores a new value, the migration replaces the old value in the rows. A table or column is renamed only when its [control policy](/orm/contract-authoring/psl-syntax#control-policy) is `managed` in both contracts. + +Because nothing is asked, a `--delete` for such a change fails with `CLI.CONSENT_UNUSED`. If you want an empty table under the new name instead, make two changes, each planned and applied before the next: remove the model and answer `--delete`, then add it back with its new `@@map`. + +Some changes cannot be made in one step, and are refused with `MIGRATION.PLANNING_FAILED`: + +- two models or fields that trade tables or columns; +- a model or field that moves to a name another one gives up in the same change; +- a model or field that takes over the table or column of one the change removes; +- enum members that trade stored values; +- an enum member that takes the stored value of a member the change removes. + +Make each of these changes in two steps, planned and applied one after the other. For a trade, or a name another one gives up, go through a name nothing uses, such as `prisma_swap_users`. For a takeover, first remove the model, field or enum member that holds the name, then add the new one in the second step. If that first step removes an enum member and you answer `--delete`, a required column cannot keep the rows that hold the member: delete those rows, or set them to a value the enum keeps, before the step is applied. + +On MySQL and MongoDB, a changed stored name is handled as it was on every database before `8.0.0-rc.25`: a changed `@@map` is planned as dropping the table and creating an empty one, and asks for `--delete`. + On PostgreSQL, a changed `onDelete` or `onUpdate` on a relation is planned as dropping the foreign key and adding it back with the new actions. A changed or removed primary key is planned the same way, and because PostgreSQL does not drop a primary key while a foreign key points at it, the migration first drops every foreign key that points at the old key, then adds back each one the new contract still declares. A foreign key the new contract leaves out stays dropped. When such a foreign key is on a table the migration must not change, such as a table whose model has an [`@@control(...)`](/orm/contract-authoring/psl-syntax#control-policy) value other than `managed`, or a table in a schema the contract no longer declares, the command refuses and names that foreign key. Before `8.0.0-rc.20`, both changes failed with `MIGRATION.PLANNING_FAILED`. On PostgreSQL, a namespace is renamed, moved or removed with the same flags. `--rename billing:finance` renames the schema, and everything in it stays in it. `--rename public.Invoice:billing.Invoice` moves the model's table to another schema with its rows, constraints, indexes and policies, and creates the schema first when the database does not have it. Namespace renames run before the other renames, whatever order you give them in. `public` and a schema another contract space declares are not renamed. @@ -83,12 +115,12 @@ A namespace is a PostgreSQL schema that your contract declares with a `namespace The command leaves alone a schema that no contract declared, such as Supabase's `auth`, and a namespace that only another contract space declares. Before `8.0.0-rc.20`, the command did not ask about a removed namespace and left its tables in place. -On PostgreSQL and SQLite, removing a member from an `enum` block, or changing the value a member stores, is asked about too, because rows may hold the old value. The command asks once for each value, however many columns hold it: +On PostgreSQL and SQLite, removing a member from an `enum` block is asked about too, because rows may hold its value. The command asks once for each value, however many columns hold it: - If you renamed the member, answer with `--rename Status.ARCHIVED:Status.RETIRED`. The migration changes the stored value in every column and list that holds it. - To let the value go, answer with `--delete Status.ARCHIVED`. Optional columns that hold it are set to `NULL`, and lists lose it. A required column cannot take `NULL`, so while any of its rows hold the value, the apply fails with `MIGRATION.PRECHECK_FAILED` before it changes anything. The error counts those rows and says how to keep them. -A member you rename while keeping its stored value, such as `RETIRED = "archived"` in place of `ARCHIVED = "archived"`, changes no rows, so nothing is asked. A member that keeps its name but stores a new value, and two members that swap their stored values, can only be answered with `--delete`. To keep those rows, the question names the `this.removeStoredValue(...)` call in the planned `migration.ts` to replace with `this.replaceStoredValue(...)` calls, and the `node migration.ts` command that runs it. [Stored enum values](/orm/reference/migration-api#stored-enum-values) in the migration API reference shows both calls. +A member you rename while keeping its stored value, such as `RETIRED = "archived"` in place of `ARCHIVED = "archived"`, changes no rows, so nothing is asked. A member that keeps its name but stores a new value is [a changed stored name](#a-changed-stored-name): the migration replaces the value in the rows and asks nothing. Two members that swap their stored values are refused; make the swap in two migrations through a value nothing uses. A member that takes the stored value of a member you remove is refused too; remove the old member in one migration and add the new one in the next. [Stored enum values](/orm/reference/migration-api#stored-enum-values) in the migration API reference shows the calls a migration uses. Native PostgreSQL enums (`pg.enum(...)`) are not affected. Before `8.0.0-rc.21`, PostgreSQL failed at apply when a row held the removed value, and SQLite planned nothing. @@ -105,13 +137,22 @@ A [variant](/orm/contract-authoring/psl-syntax#base-models-and-variants) whose d - `--rename Bug:Defect` of a variant whose value also changed rewrites the value in the same way. - `--delete Bug` deletes the rows that hold the old value, then drops a removed variant's own table or the columns only it used. -On MongoDB, `--rename` of a value object field or of a variant whose discriminator value changes is refused, and so are `--convert` of a variant and `--backfill` of a value object field. +On MongoDB, changes inside documents are asked about too, since `8.0.0-rc.25`: + +- A field that a value object or an embedded model loses: `--rename Address.street:Address.line1` if you renamed it, or `--delete Address.street` to remove the key from every stored object. +- A stored value that an enum loses: `--rename Status.ARCHIVED:Status.RETIRED` to keep the documents under another member, or `--delete Status.ARCHIVED` to unset it in optional fields and take it out of lists. Where a required field holds it, the apply stops with `MIGRATION.PRECHECK_FAILED`, counts the documents, and says how to keep them. +- A variant whose discriminator value changes: `--convert Bug` to rewrite the value, or `--delete Bug` to delete its documents. +- A variant the contract removes: `--rename Bug:Issue` if you renamed it, or `--delete Bug` to delete its documents. + +A new required field inside a value object or an embedded model is not asked about: the migration gives it a temporary value in the objects that lack it, as it does for a new required field of a model, described below. A field whose type has no temporary value, a field that holds one value object, and a field that a unique index covers get no temporary value, so plan them with `--backfill Address.zip`, naming the field. A new required list gets an empty list. To write your own value, pass `--backfill Address.zip` and replace the placeholder in the migration with an aggregation expression, such as `{ $literal: 'unknown' }`. + +On MongoDB, make a change in two migrations when one part of it writes a field, key or value that another part reads, such as two renames that trade names. `migration plan` refuses such a change in one migration, because MongoDB applies the operations one at a time. -On MongoDB, a field type change that can lose values is asked about, as on SQL, and it has two answers. `--delete User.age` casts the stored values with `$convert` and stops on a value it cannot cast. `--convert User.age` writes a data transform that holds `placeholder('User.age:update')`, which you replace with your own update document or aggregation pipeline; [MongoDB operations](/orm/reference/migration-api#mongodb-operations) shows the planned transform. A change such as `String` to `Boolean`, which `$convert` would get wrong, offers `--convert` only. A cast that keeps every value, such as `Int32` to `Int64`, is planned with nothing asked. +On MongoDB, a field type change that can lose values is asked about, as on SQL, and it has two answers. `--delete User.age` casts the stored values with `$convert` and stops on a value it cannot cast. `--convert User.age` writes a data transform that holds `placeholder('User.age:update')`, which you replace with your own update document or aggregation pipeline; [MongoDB operations](/orm/reference/migration-api#mongodb-operations) shows the planned transform. A change such as `String` to `Boolean`, which `$convert` would get wrong, offers `--convert` only. A cast that keeps every value, such as `Int` to `BigInt`, is planned with nothing asked. A new required field on MongoDB is filled with a temporary value in the documents that lack it: `""` for a `String`, `0` for a number, and `false` for a `Boolean`. A field of another type, such as a `DateTime`, has no temporary value, so plan it with `--backfill`. Without `--backfill`, `migration plan` writes no fill for such a field and prints no warning, and `db migrate` stops at the validator change with `MIGRATION.PRECHECK_FAILED`, naming the `--backfill` flag. To set your own value instead, pass `--backfill User.plan`, which writes a data transform for it. A new required field that a unique index covers gets no temporary value, so plan it with `--backfill`. A change to a collection's validator checks the documents before it applies; see [how migrations work](/orm/migrations/how-migrations-work#the-same-model-for-sql-and-mongodb). This paragraph and the one before it apply since `8.0.0-rc.24`. -On MongoDB, a model rename renames its collection and keeps its documents, indexes and validator, and a field rename renames the field in every document that holds it. Removing a field from a model removes it from every document that holds it, so the command asks about it as it asks about a dropped collection: answer with `--delete User.nickname` or `--rename User.nickname:User.`. The planner refuses a rename of the field stored as `_id`, of a field whose stored name contains `.` or starts with `$`, of a time-series collection, and of a variant whose discriminator value changes, and says what to do instead. +On MongoDB, a model rename renames its collection and keeps its documents, indexes and validator, and a field rename renames the field in every document that holds it. Removing a field from a model removes it from every document that holds it, so the command asks about it as it asks about a dropped collection: answer with `--delete User.nickname` or `--rename User.nickname:User.`. The planner refuses a rename of the field stored as `_id`, of a field whose stored name contains `.` or starts with `$`, and of a time-series collection, and says what to do instead. On MongoDB, `--rename` and `--delete` name fields by their names in the schema, not by the names they are stored under. For a field `id ObjectId @id @map("_id")`, write `--rename User.id:User.userId`, not `User._id`. diff --git a/apps/docs/content/docs/cli/migration-ref.mdx b/apps/docs/content/docs/cli/migration-ref.mdx index 163d88b40b8..91f15f608fa 100644 --- a/apps/docs/content/docs/cli/migration-ref.mdx +++ b/apps/docs/content/docs/cli/migration-ref.mdx @@ -8,7 +8,7 @@ metaDescription: 'Learn how to set, list, and delete named Prisma ORM contract r A ref is a name, such as `staging` or `production`, for the contract state an environment should match. The contract is your schema as [`contract emit`](/cli/contract-emit) writes it to `contract.json`, and each version of it has a hash. Use refs when an environment should be migrated to a state you choose instead of to your latest migration. Other commands then take the name in place of a contract hash: [`db migrate --to production`](/cli/db-migrate), [`db update --to production`](/cli/db-update), or [`db sign production`](/cli/db-sign). -`migration ref set` accepts only a contract that one of your migrations produces, so plan a migration for a change before you set a ref to it. `db init`, `db update`, and `db sign` can update a ref to a contract that no migration produces. Each ref is a file in your migrations folder, by default `migrations/app/refs/.json`, so commit it with your migrations. The `migration ref` commands change only these files and never connect to a database. +`migration ref set` accepts only a contract that one of your migrations produces, so plan a migration for a change before you set a ref to it. `db init`, `db update`, and `db sign` can update a ref to a contract that no migration produces. Each ref is a file in your migrations folder, by default `migrations/app/refs/.json`, so commit it with your migrations. A ref file can also declare, in a `policies` key, the [policies](/orm/migrations/database-policies#declare-policies-in-a-ref) its database should have. The commands that rewrite a ref file keep that key. The `migration ref` commands change only these files and never connect to a database. ## The db ref @@ -18,7 +18,7 @@ These commands update the `db` ref for you: - [`db init`](/cli/db-init) and [`db update`](/cli/db-update) update it when they take the connection from `prisma.config.ts`. When you pass `--db`, they update it only if you also pass `--advance-ref db`. With `--advance-ref `, they update that ref instead. - [`db sign`](/cli/db-sign) updates it after it succeeds, with or without `--db`. Pass `--no-advance-ref` to stop it, or `--advance-ref ` to update that ref instead. -- [`db migrate`](/cli/db-migrate) updates it only when you pass `--advance-ref db`. Without that flag it never changes the file, so a deploy or CI run leaves your repository unchanged. In CI, run `db init` and `db update` with `--db` for the same reason. +- [`db migrate`](/cli/db-migrate) updates it when it takes the connection from `prisma.config.ts` and does not detect CI. With `--db` or in CI, it updates it only if you also pass `--advance-ref db`. `--no-advance-ref` stops it in every case. A CI run, or a run with `--db`, therefore leaves your repository unchanged, while a deploy that is not a CI job and reads its connection from `prisma.config.ts` needs `--no-advance-ref`. In CI, run `db init` and `db update` with `--db` for the same reason. You can also set it yourself with `migration ref set db `. diff --git a/apps/docs/content/docs/cli/migration-status.mdx b/apps/docs/content/docs/cli/migration-status.mdx index c9fdad59d50..348cd841051 100644 --- a/apps/docs/content/docs/cli/migration-status.mdx +++ b/apps/docs/content/docs/cli/migration-status.mdx @@ -65,7 +65,7 @@ When you do not pass `--db`, the command connects to `db.connection` in `prisma. ⚠ 1 pending — run `prisma db migrate --to a4c3fa7fc3b2` ``` -Read the drawing from the bottom up, because the earliest state is the bottom row. `∅` is the empty database, before any migration. `@contract` marks the contract in `contract.json`. `@db` marks the contract state that the database's marker records. `(db)` is the `db` [ref](/cli/migration-ref), the file `migrations/app/refs/db.json`, which records the contract state your development database is at. [`db init`](/cli/db-init) writes that file, and so does `db migrate --advance-ref db`. In this output `@db` and `(db)` are on the same row, because the marker and the `db` ref name the same state. [Check before, preview, then apply](/orm/migrations/applying-a-migration#check-before-preview-then-apply) explains each row and each label in more detail. +Read the drawing from the bottom up, because the earliest state is the bottom row. `∅` is the empty database, before any migration. `@contract` marks the contract in `contract.json`. `@db` marks the contract state that the database's marker records. `(db)` is the `db` [ref](/cli/migration-ref), the file `migrations/app/refs/db.json`, which records the contract state your development database is at. [`db init`](/cli/db-init) writes that file, and so does `db migrate`. In this output `@db` and `(db)` are on the same row, because the marker and the `db` ref name the same state. [Check before, preview, then apply](/orm/migrations/applying-a-migration#check-before-preview-then-apply) explains each row and each label in more detail. The last line suggests the command to run next. It names the pending state by the first 12 characters of its hash, `a4c3fa7fc3b2`, which is the same hash the drawing shortens to 7 characters, `a4c3fa7`. diff --git a/apps/docs/content/docs/cli/orm-init.mdx b/apps/docs/content/docs/cli/orm-init.mdx index cfee9308ac8..c05f92d1466 100644 --- a/apps/docs/content/docs/cli/orm-init.mdx +++ b/apps/docs/content/docs/cli/orm-init.mdx @@ -28,14 +28,14 @@ npx prisma@latest orm init --yes --target postgres --authoring psl | Option | What it does | | --- | --- | -| `--target ` | Sets the database target. Use `postgres` or `mongodb`. | +| `--target ` | Sets the database target: `postgres`, `mongodb`, or the name of a target package, such as `@prisma/orm-sqlite` or `@prisma/orm-mysql`. See [Set up another database with a target package](#any-target-package). | | `--authoring