技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
prisma-upgrade-v7【数据与研究】Use when migrating an existing Prisma ORM SQL project from v6 to v7, updating generated-client imports, driver adapters, module format, or configuration.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Complete guide for migrating from Prisma ORM v6 to v7. This upgrade introduces significant breaking changes around the new prisma-client generator, driver adapters, prisma.config.ts, explicit environment loading, and generated client entrypoints.
Reference this skill when:
prisma-client generatorprisma.config.ts| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Schema Migration | CRITICAL | schema-changes |
| 2 | Database Connectivity | CRITICAL | driver-adapters |
| 3 | Module System | CRITICAL | esm-support |
| 4 | Config and Env | HIGH | prisma-config, env-variables |
| 5 | Removed Features | HIGH | removed-features |
| 6 | Accelerate | HIGH | accelerate-users |
schema-changes - generator migration, required output paths, generated entrypoints, and Prisma.validator replacementdriver-adapters - required adapter installation for SQL providers, pool differences, and Prisma Postgres adapter choicesesm-support - ESM-first setup plus CommonJS fallback with moduleFormat = "cjs"prisma-config - creating and using prisma.config.tsenv-variables - explicit environment loadingremoved-features - removed middleware, metrics, and legacy CLI behavioraccelerate-users - migration notes for Accelerate usersPrisma 7 has no MongoDB connector. Do not apply any step in this guide to a project with
provider = "mongodb" — see the prisma-mongodb-upgrade skill for the actual decision
(stay on v6 deliberately vs migrate to Prisma 8).
prisma-mongodb-upgrade)7.6.0; inspect the project lockfile and current official release notes before selecting the target version.esm by default, cjs if needed)prisma.config.tsPrisma.validatorprisma generate and test# Update packages
npm install @prisma/client@7
npm install -D prisma@7
# Install a driver adapter (PostgreSQL or Prisma Postgres via direct TCP)
npm install @prisma/adapter-pg pg
# Install dotenv for env loading
npm install dotenv
# Regenerate client
npx prisma generate
| Change | v6 | v7 |
|---|---|---|
| Module format | Implicit / mixed | ESM-first, moduleFormat = "cjs" supported |
| Generator provider | prisma-client-js | prisma-client is the default, while prisma-client-js still exists for legacy setups |
| Output path | Auto (node_modules) | Required explicit |
| Driver adapters | Optional | Required for SQL providers |
| Config file | .env + schema | prisma.config.ts |
| Env loading | Automatic | Manual (dotenv) |
| Generated entrypoints | Single package export | client, browser, models, enums entrypoints |
| Type-safe query fragments | Prisma.validator() | TypeScript satisfies |
| Middleware | $use() | Client Extensions |
| Metrics | Preview feature | Removed |
Detailed migration guides for each breaking change:
references/esm-support.md - ESM and CommonJS configuration
references/schema-changes.md - Generator, output, imports, and generated entrypoints
references/driver-adapters.md - Required driver adapter setup
references/prisma-config.md - New configuration file
references/env-variables.md - Environment variable loading
references/removed-features.md - Middleware, metrics, and CLI flags
references/accelerate-users.md - Special handling for Accelerate
{
"type": "module"
}
If you need to stay on CommonJS, keep your app as CJS and set moduleFormat = "cjs" in the generator block instead of forcing ESM.
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "bundler",
"target": "ES2023",
"strict": true,
"esModuleInterop": true
}
}
// Before (v6)
generator client {
provider = "prisma-client-js"
}
// After (v7)
generator client {
provider = "prisma-client"
output = "../generated/prisma"
// Optional if you need CommonJS:
// moduleFormat = "cjs"
}
import 'dotenv/config'
import { defineConfig, env } from 'prisma/config'
export default defineConfig({
schema: 'prisma/schema.prisma',
migrations: {
path: 'prisma/migrations',
},
datasource: {
url: env('DATABASE_URL'),
},
})
# PostgreSQL
npm install @prisma/adapter-pg pg
# MySQL
npm install @prisma/adapter-mariadb mariadb
# SQLite
npm install @prisma/adapter-better-sqlite3 better-sqlite3
# Prisma Postgres in standard Node.js apps (recommended)
npm install @prisma/adapter-pg pg
# Prisma Postgres serverless driver (edge/serverless)
npm install @prisma/adapter-ppg @prisma/ppg
# Neon
npm install @prisma/adapter-neon
MongoDB does not have a SQL @prisma/adapter-* package in the published Prisma 7.6.0 packages. If you're upgrading a MongoDB project, stop and keep that project on the latest Prisma 6.x release instead of following the standard Prisma 7 migration path.
// Before (v6)
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
// After (v7)
import { PrismaClient } from '../generated/prisma/client'
import { PrismaPg } from '@prisma/adapter-pg'
const adapter = new PrismaPg({
connectionString: process.env.DATABASE_URL
})
const prisma = new PrismaClient({ adapter })
import { Prisma } from '../generated/prisma/client'
const userSelect = {
id: true,
email: true,
name: true,
} satisfies Prisma.UserSelect
npx prisma generate
npx prisma migrate dev # if needed
output path matches your import pathprisma generate ran successfullyssl: { rejectUnauthorized: false } to the adapter config if you need to preserve old behaviorNODE_EXTRA_CA_CERTS / OpenSSL CA settingsFollow references/schema-changes.md and references/driver-adapters.md first, then apply the remaining reference files based on your project setup.
This is a reviewed overlay of the pinned MIT-licensed official skill.
Record the installed CLI/client versions, database provider, module format,
connection method and deployment target before selecting upgrade steps.
The MongoDB boundary above is a route decision, not permission to change providers.
The optional prisma-mongodb-upgrade skill is not bundled here; use official
MongoDB guidance if it is absent. Do not apply the SQL migration to MongoDB.
Run generation, typechecking and focused database integration tests on an isolated development database. Verify transaction rollback and pool behavior. Review migration SQL before applying it; record backup and recovery steps for production changes. The reset examples in removed-features.md are destructive and apply only to disposable development databases explicitly selected for reset. Do not infer authorization to reset or migrate production from an ORM upgrade. Record the accepted target version in the lockfile and release notes.