Skip to content

Commit 72aa5e3

Browse files
authored
feat: add prisma-mongodb-upgrade skill (#20)
* feat: add prisma-mongodb-upgrade skill MongoDB projects are the one Prisma cohort with no path to Prisma 7 (v6 is the terminal classic-ORM major for MongoDB; v7 ships no connector). Agents routinely mis-advise these projects: recommending an impossible v7 upgrade or silently rewriting apps onto SQL. This skill frames the real decision — stay on the latest v6 deliberately (the default for production today) or migrate to Prisma Next — and carries the migration mechanics: schema-to-contract mapping, client API mapping including the raw lanes and the transactions gap, migrations story, and a no-data-moves cutover checklist. Prisma Next claims are verified against prisma/prisma-next at commit a2791c5dd59d579b4b3052942ae7f8fe5e2ee852; v6 claims cite released v6 documentation. Cross-links added: prisma-upgrade-v7 and prisma-database-setup now route MongoDB version questions to this skill, and the README gains the skill entry. Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net> * docs: reframe mongodb skill around Early Access status Correct the maturity framing per review: MongoDB support in Prisma Next is Early Access with GA planned after Postgres, and migrating is the encouraged path for MongoDB users; staying on v6 remains a legitimate choice where hard blockers apply, stated without discouraging framing. Blocker questions become agent self-checks (grep for $transaction instead of asking the user). Transactions guidance now states affirmatively that the underlying mongodb driver is directly available for sessions today, with the facade wrapper expected soon. Internal prisma-next source paths removed from user-facing prose in favor of Prisma Next's own skills. Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net> * docs: soften the example dialogue line per review suggestion Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net> * docs: clarify MongoDB upgrade path Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net> --------- Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
1 parent dc08577 commit 72aa5e3

9 files changed

Lines changed: 443 additions & 2 deletions

File tree

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ Step-by-step migration guide from Prisma v6 to v7, covering all breaking changes
4545

4646
---
4747

48+
### prisma-mongodb-upgrade
49+
50+
Decision and migration guide for MongoDB projects on Prisma v6, which have no path to Prisma 7.
51+
52+
**Use when:**
53+
- A MongoDB project asks about upgrading Prisma versions
54+
- Evaluating a move from Prisma v6 to Prisma Next
55+
- Preventing an impossible "upgrade MongoDB to v7" plan
56+
57+
**Topics covered:**
58+
- The version landscape (v6 terminal for MongoDB; v7 has no connector; Prisma Next is the successor path)
59+
- Stay-on-v6 vs migrate-now decision table with no-go signals
60+
- Schema/contract, client API, and migrations mapping between v6 and Prisma Next
61+
- No-data-moves cutover verification checklist
62+
63+
---
64+
4865
### prisma-client-api
4966

5067
Comprehensive Prisma Client API reference.
@@ -160,6 +177,7 @@ Or install specific skills:
160177
```bash
161178
npx skills add prisma/skills --skill prisma-cli
162179
npx skills add prisma/skills --skill prisma-upgrade-v7
180+
npx skills add prisma/skills --skill prisma-mongodb-upgrade
163181
npx skills add prisma/skills --skill prisma-client-api
164182
npx skills add prisma/skills --skill prisma-driver-adapter-implementation
165183
npx skills add prisma/skills --skill prisma-database-setup

prisma-database-setup/SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ generator client {
170170
}
171171
```
172172

173-
For MongoDB, stay on the latest Prisma 6.x line and keep the connection URL in `schema.prisma`. Do not move a MongoDB project to the Prisma 7 SQL adapter setup.
173+
For MongoDB, stay on the latest Prisma 6.x line and keep the connection URL in `schema.prisma`. Do not move a MongoDB project to the Prisma 7 SQL adapter setup. If a MongoDB project asks about upgrading Prisma versions, route to the `prisma-mongodb-upgrade` skill (stay-on-v6 vs Prisma Next is the real decision; Prisma 7 is not an option).
174174

175175
## Rule Files
176176

prisma-mongodb-upgrade/SKILL.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
name: prisma-mongodb-upgrade
3+
description: Decision and migration guide for Prisma ORM MongoDB projects on v6, which have no upgrade path to v7. Use when a MongoDB project asks about upgrading Prisma, when "upgrade to prisma 7" comes up in a project with provider = "mongodb", or when evaluating a move to Prisma Next. Triggers on "upgrade prisma mongodb", "prisma 7 mongodb", "mongodb prisma migration", "prisma next mongodb".
4+
license: MIT
5+
metadata:
6+
author: prisma
7+
version: "0.1.0"
8+
---
9+
10+
# Prisma MongoDB Upgrade Path
11+
12+
MongoDB projects are the one Prisma cohort with no road into Prisma 7: **v6 is the terminal
13+
classic-ORM major for MongoDB, and v7 never ships a MongoDB connector**. The successor path
14+
is [Prisma Next](https://github.com/prisma/prisma-next), where MongoDB support is in Early
15+
Access with GA planned after Postgres. This skill frames the real decision — migrate to
16+
Prisma Next (the encouraged path), or stay on v6 where a hard blocker applies — and carries
17+
the migration mechanics.
18+
19+
**Never do either of these:**
20+
21+
- Never advise a MongoDB project to "upgrade to Prisma 7". The connector does not exist
22+
there. The `prisma-upgrade-v7` guide does not apply to MongoDB projects.
23+
- Never solve the version question by rewriting the app onto a SQL database. Changing the
24+
database engine is a separate, much larger decision that is not yours to make implicitly.
25+
26+
## The version landscape
27+
28+
| Version | MongoDB status |
29+
|---------|----------------|
30+
| Prisma ORM v6 | Fully supported (`mongodb` provider); latest 6.x is the current stable path; maintenance line |
31+
| Prisma ORM v7 | **No MongoDB connector — not an option, ever** |
32+
| Prisma Next | MongoDB support in **Early Access**, actively developed, GA planned after Postgres — the successor path for MongoDB projects |
33+
34+
## The decision, up front
35+
36+
**Migrating to Prisma Next is the encouraged path.** MongoDB support in Prisma Next is Early
37+
Access: functional and moving quickly, with GA planned after Postgres — and the Prisma team
38+
wants MongoDB users to migrate early and share feedback. The migration mechanics are
39+
detailed in the references.
40+
41+
**Staying on the latest v6 remains a legitimate choice where a hard blocker applies**
42+
stated plainly: the Next Mongo façade does not wrap transactions yet (the underlying driver
43+
is available directly; this is expected to change soon), and pre-1.0 minors can carry
44+
breaking changes with published upgrade recipes.
45+
46+
### Decision table
47+
48+
| Signal | Direction |
49+
|--------|-----------|
50+
| No blockers below apply | Migrate to Next; run the `verify-cutover-checklist` and share feedback with the Prisma team |
51+
| Greenfield / prototype / internal tool | Migrate to Next |
52+
| Codebase uses multi-document transactions (`$transaction`) — check with grep, do not ask | Plan raw-driver session equivalents first (see `client-api-mapping`), or stay on v6 until the façade wrapper lands |
53+
| Team cannot absorb pre-1.0 breaking upgrades between minors | Stay on v6 until GA |
54+
| Risk-averse but interested | Run a staged Next round-trip on a copy (see `verify-cutover-checklist`), then migrate |
55+
56+
Note: the transactions gap is expected to close soon — this section will be updated when
57+
façade transactions merge in Prisma Next.
58+
59+
### If staying on v6: hygiene (a deliberate stay, not neglect)
60+
61+
- Pin the Prisma packages to the latest 6.x line and keep taking 6.x patch releases.
62+
- Track Prisma release notes and security advisories for the 6.x line.
63+
- Keep the classic v6 MongoDB setup: `url = env("DATABASE_URL")` in the schema, `db push`
64+
workflow, no SQL driver adapters (see `prisma-database-setup` for the v6 MongoDB shape).
65+
- Re-evaluate when Prisma Next's MongoDB is GA, or when blockers for trying EA are resolved.
66+
67+
## Reference files
68+
69+
| Reference | What it covers |
70+
|-----------|----------------|
71+
| `references/decision-stay-or-migrate.md` | The full decision framing, blocker checks, and stay-hygiene detail |
72+
| `references/schema-contract-mapping.md` | v6 schema (`mongodb` provider, `@db.ObjectId`, composite types) → Next contract concepts |
73+
| `references/client-api-mapping.md` | v6 client calls → Next equivalents, incl. raw escape hatches and transactions — names map, parity does not |
74+
| `references/migrations-mapping.md` | v6 `db push`-only story → Next's plan/migrate/verify/sign flow |
75+
| `references/verify-cutover-checklist.md` | No-data-moves verification: same DB, index parity, staged round-trip before cutover |
76+
77+
## Verified against
78+
79+
Behavioral claims about Prisma Next in this skill were verified against
80+
[prisma/prisma-next](https://github.com/prisma/prisma-next) at commit
81+
`a2791c5dd59d579b4b3052942ae7f8fe5e2ee852` (pre-1.0, ~v0.14/0.15 line). Prisma Next moves
82+
quickly in Early Access: **before acting on any Next-side claim, verify it against the
83+
version actually installed** (check the project's `@prisma-next/*` versions and the
84+
prisma-next skills installed with it). Next's Mongo target requires MongoDB 8.0+ and expects
85+
`mongodb@^7` as a user-supplied peer dependency.
86+
87+
## Hand-off rule
88+
89+
This skill is the **discovery bridge**, not a replacement for Prisma Next's own
90+
documentation. After a project switches to Prisma Next, run Prisma Next's `init`/skill
91+
installation and follow its own skills (quickstart, contract, queries, migrations, runtime)
92+
for day-to-day work — do not keep working from this skill's summaries.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# client-api-mapping
2+
3+
How v6 Prisma Client calls map to Prisma Next's Mongo client — names map, parity does not.
4+
5+
## Priority
6+
7+
CRITICAL
8+
9+
## Why It Matters
10+
11+
The v6 and Next client APIs look superficially similar, but none of the v6 MongoDB raw
12+
methods exist under their old names, aggregation moved to a different lane entirely, and
13+
transactions go through the driver rather than a façade wrapper. Assuming parity produces
14+
code that does not compile — or, in the transactions case, code that silently loses
15+
atomicity.
16+
17+
## The mapping
18+
19+
| v6 call | Prisma Next equivalent | Notes |
20+
|---------|------------------------|-------|
21+
| `prisma.user.findMany(...)` | `db.orm.users.where(...).all()` | Fluent ORM lane; storage-name keys (see `schema-contract-mapping.md`) |
22+
| `prisma.user.findFirst(...)` | `db.orm.users.where(...).first()` | |
23+
| `create` / `update` / `upsert` / `delete` / `updateMany` / `deleteMany` | `create` / `update` / `upsert` / `delete` / `updateAll` / `deleteAll` on `db.orm.<collection>` | See Prisma Next's `prisma-next-queries` skill |
24+
| `prisma.user.aggregate(...)`, `groupBy(...)` | **No ORM equivalent.** Use the typed aggregation-pipeline builder: `db.query.from(...).match(...).group(...).build()` | Prisma Next's `prisma-next-queries` skill covers the builder lane |
25+
| `$runCommandRaw(...)` ([v6 docs](https://www.prisma.io/docs/orm/prisma-client/using-raw-sql/raw-queries#runcommandraw)) | **Name does not exist in Next.** Raw lane is `mongoRaw(...)` → a raw collection with `aggregate`, `insertOne/Many`, `updateOne/Many`, `deleteOne/Many`, `findOneAndUpdate/Delete`. For arbitrary database commands, use the underlying `mongodb` driver directly — it is a user-supplied peer dependency and fully accessible | Check the installed version's raw surface |
26+
| `<model>.findRaw(...)` ([v6 docs](https://www.prisma.io/docs/orm/prisma-client/using-raw-sql/raw-queries#findraw)) | `mongoRaw(...)` collection reads (e.g. `aggregate` with a `$match` stage) | No direct `findRaw` name |
27+
| `<model>.aggregateRaw(...)` ([v6 docs](https://www.prisma.io/docs/orm/prisma-client/using-raw-sql/raw-queries#aggregateraw)) | `mongoRaw(...).aggregate(...)` or the typed pipeline builder | |
28+
| `$transaction(...)` — works on v6 with a replica set ([v6 docs](https://www.prisma.io/docs/orm/overview/databases/mongodb#replica-set-configuration)) | The façade does not wrap `db.transaction(...)` yet, **but the underlying `mongodb` driver is directly available** (user-supplied peer dependency): multi-document atomicity works today via driver sessions (`client.startSession()` / `session.withTransaction(...)`) on a replica set | A façade wrapper is expected soon; this row will be updated when it merges |
29+
| `$connect` / `$disconnect` | `connect()` / `close()` on the Mongo façade client | |
30+
31+
## Bad
32+
33+
```typescript
34+
// Assuming v6 names exist in Prisma Next:
35+
await db.user.$runCommandRaw({ collStats: 'users' }); // no such method
36+
await db.transaction(async (tx) => { ... }); // no such method on the Mongo façade
37+
```
38+
39+
## Good
40+
41+
```typescript
42+
// Raw lane under its Next name:
43+
const raw = mongoRaw(db);
44+
await raw.users.aggregate([{ $match: { status: 'active' } }]);
45+
46+
// Aggregation through the typed pipeline builder:
47+
const stats = await db.query.from('users').group({ _id: '$role', n: { $count: {} } }).build();
48+
49+
// Multi-document atomicity today: the mongodb driver (a direct dependency of the
50+
// project) exposes sessions and transactions as usual:
51+
const session = mongoClient.startSession();
52+
await session.withTransaction(async () => {
53+
// ...writes...
54+
});
55+
```
56+
57+
## References
58+
59+
- [v6 MongoDB raw queries](https://www.prisma.io/docs/orm/prisma-client/using-raw-sql/raw-queries#raw-queries-with-mongodb)
60+
- [v6 replica set requirement for transactions](https://www.prisma.io/docs/orm/overview/databases/mongodb#replica-set-configuration)
61+
- Prisma Next queries + runtime skills (`skills/prisma-next-queries`, incl. its dedicated `mongo.md`; `skills/prisma-next-runtime`) — authoritative for the Next side; verified @ `a2791c5dd59d579b4b3052942ae7f8fe5e2ee852`
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# decision-stay-or-migrate
2+
3+
How to decide between migrating a MongoDB project to Prisma Next and staying on Prisma v6.
4+
5+
## Priority
6+
7+
CRITICAL
8+
9+
## Why It Matters
10+
11+
MongoDB projects cannot follow the general "upgrade Prisma" advice: Prisma 7 has no MongoDB
12+
connector, so the forward path is Prisma Next. Advising an impossible v7 upgrade, or
13+
silently rewriting the app onto SQL, are both serious failure modes. The encouraged path is
14+
migrating to Prisma Next — its MongoDB support is Early Access and the Prisma team wants
15+
early adopters' feedback — with a deliberate stay on v6 where a hard blocker applies.
16+
17+
## The facts the decision rests on
18+
19+
Prisma Next side (verified against prisma/prisma-next @ `a2791c5dd59d579b4b3052942ae7f8fe5e2ee852`;
20+
status confirmed by the Prisma team 2026-07):
21+
22+
- **MongoDB support is Early Access**, actively developed, with GA planned after Postgres.
23+
- The implementation is deep, not a stub: a full package family (ORM, typed
24+
aggregation-pipeline builder, raw lane, driver over the official `mongodb` package),
25+
first-class contract-driven migrations, and extensive tests against real in-memory MongoDB.
26+
- **The Mongo client façade does not wrap `db.transaction(...)` yet** — multi-document
27+
atomicity is done through the MongoDB driver's session API, which is directly available
28+
(the `mongodb` package is a user-supplied peer dependency). A façade wrapper is expected;
29+
this skill will be updated when it merges.
30+
- Early Access means pre-1.0 minors can carry breaking changes, with published upgrade
31+
recipes (e.g. 0.11→0.12 changed Mongo validator emission and made `mongodb` a
32+
user-supplied peer dependency). Floor: MongoDB 8.0 and `mongodb@^7`.
33+
34+
Prisma v6 side:
35+
36+
- v6 fully supports MongoDB, including transactions on replica sets — "MongoDB only allows
37+
you to start a transaction on a replica set. Prisma ORM uses transactions internally"
38+
([replica set configuration](https://www.prisma.io/docs/orm/overview/databases/mongodb#replica-set-configuration)).
39+
- v6 MongoDB has no Prisma Migrate; the workflow is `db push`
40+
([no support for Prisma Migrate](https://www.prisma.io/docs/orm/overview/databases/mongodb#no-support-for-prisma-migrate)).
41+
42+
## Blocker checks before migrating
43+
44+
Run these checks yourself — from the codebase, not by asking the user:
45+
46+
- **Search the codebase for `$transaction` usage** (grep for `$transaction`). If present,
47+
plan the raw-driver session equivalents before migrating (see `client-api-mapping.md`) —
48+
or stay on v6 until the façade wrapper lands.
49+
- **Check the MongoDB server version** (must be 8.0+ for Next; v6 tolerated older).
50+
- **Confirm the team can absorb pre-1.0 upgrades.** Next publishes versioned upgrade recipes
51+
between minors; someone has to run them. For a production app, confirm the user accepts
52+
Early Access status before migrating.
53+
54+
## Bad
55+
56+
```text
57+
User: "We're on Prisma 6 with MongoDB. Should we upgrade to Prisma 7?"
58+
Agent: "Yes — here's the v7 upgrade guide. Step 1: install a driver adapter..."
59+
```
60+
61+
Prisma 7 has no MongoDB connector; this migration is impossible and the SQL driver-adapter
62+
steps corrupt a working v6 setup.
63+
64+
## Good
65+
66+
```text
67+
User: "We're on Prisma 6 with MongoDB. Should we upgrade to Prisma 7?"
68+
Agent: "Prisma 7 does not support MongoDB — v6 is the last classic-ORM
69+
major for MongoDB. The path forward is Prisma Next, the successor: its MongoDB support is
70+
Early Access and migrating is encouraged. Let me check the codebase for blockers first —
71+
searching for $transaction usage and checking the MongoDB server version..."
72+
```
73+
74+
## Stay-on-v6 hygiene
75+
76+
Staying is a decision, not a default-by-neglect:
77+
78+
- Pin `prisma` and `@prisma/client` to the latest 6.x and keep taking 6.x patches.
79+
- Watch Prisma release notes and security advisories for the 6.x maintenance line.
80+
- Keep the classic setup (`url = env("DATABASE_URL")` in the schema; `db push`; no SQL
81+
driver adapters).
82+
- Re-evaluate when Prisma Next's MongoDB is GA, or when blockers for trying EA are resolved.
83+
84+
## References
85+
86+
- [Prisma Next repository](https://github.com/prisma/prisma-next)
87+
- [Prisma v6 MongoDB documentation](https://www.prisma.io/docs/orm/overview/databases/mongodb)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# migrations-mapping
2+
3+
How the v6 MongoDB "no migrations" story maps onto Prisma Next's first-class migration flow.
4+
5+
## Priority
6+
7+
HIGH
8+
9+
## Why It Matters
10+
11+
This is the largest workflow change in the migration — in v6, MongoDB explicitly has no
12+
Prisma Migrate, while in Prisma Next MongoDB participates in the full migration lifecycle.
13+
Teams porting a `db push` habit into Next without understanding the plan/verify/sign flow
14+
will fight the tooling or bypass its safety rails.
15+
16+
## v6: `db push` only
17+
18+
MongoDB on v6 has no Prisma Migrate and no plans to add it — "MongoDB projects do not rely
19+
on internal schemas" ([no support for Prisma Migrate](https://www.prisma.io/docs/orm/overview/databases/mongodb#no-support-for-prisma-migrate)).
20+
The workflow is `prisma db push` to sync indexes and unique constraints, with no migration
21+
history on disk.
22+
23+
## Prisma Next: first-class, contract-driven migrations (Mongo included)
24+
25+
Migration authoring in Next is first-class for Postgres **and Mongo** (prisma-next
26+
`skills/prisma-next-migrations/SKILL.md`) — MongoDB is not a push-only special case:
27+
28+
- **Flow:** contract *emit* → diff → *plan* (writes a content-hashed migration package) →
29+
*migrate* (apply in graph order) → *verify* (live schema vs destination contract) →
30+
*sign* (advance the marker after a verify pass).
31+
- **Mongo migration ops** come from dedicated factories: `createCollection`,
32+
`dropCollection`, `validatedCollection`, `setValidation`, `createIndex`, `dropIndex`,
33+
`collMod`, and `dataTransform` for data backfills.
34+
- **Marker storage:** Next records migration state in a document in the
35+
`_prisma_migrations` collection (per space) — the same collection name family v6 users
36+
know from SQL, repurposed for Mongo state.
37+
- **DDL is not transactional on Mongo:** the runner applies operations, verifies the live
38+
schema against the destination contract, and only advances the marker on a verify pass —
39+
making interrupted runs resumable rather than atomic (see Prisma Next's
40+
`prisma-next-migrations` skill).
41+
- **Push-style alternative still exists:** `db update` diffs the live database against the
42+
contract and applies directly without writing a migration directory — the closest
43+
analogue to the v6 `db push` habit, at the cost of no history.
44+
- Validators: Next emits closed `$jsonSchema` validators by default since 0.12 (prisma-next
45+
`CHANGELOG.md`) — collections gain schema enforcement v6 never applied.
46+
47+
## Bad
48+
49+
```text
50+
Porting the v6 habit: run the Next equivalent of `db push` for every change in production,
51+
accumulating no migration history, and hand-editing collections when verification fails.
52+
```
53+
54+
## Good
55+
56+
```text
57+
Adopt the Next lifecycle: emit the contract, plan a migration package, apply it with
58+
migrate, let verify gate the marker, and sign. Reserve `db update` for local prototyping,
59+
mirroring how `db push` was used on v6.
60+
```
61+
62+
## References
63+
64+
- [v6: no Prisma Migrate for MongoDB](https://www.prisma.io/docs/orm/overview/databases/mongodb#no-support-for-prisma-migrate)
65+
- Prisma Next migrations skill (`skills/prisma-next-migrations`) — authoritative for the Next side; verified @ `a2791c5dd59d579b4b3052942ae7f8fe5e2ee852`

0 commit comments

Comments
 (0)