Skip to main content

Prisma CLI

Prisma 命令行接口 (CLI) 是从命令行与 Prisma 项目交互的主要方式。它可以初始化新的项目资源,生成 Prisma 客户端,并通过内省分析现有的数据库结构,以自动创建你的应用模型。

¥The Prisma command line interface (CLI) is the primary way to interact with your Prisma project from the command line. It can initialize new project assets, generate Prisma Client, and analyze existing database structures through introspection to automatically create your application models.

命令参考

¥Command reference

有关命令的完整列表,请参阅 Prisma CLI 命令参考

¥See Prisma CLI command reference for a complete list of commands.

安装

¥Installation

Prisma CLI 通常作为开发依赖在本地安装,这就是下面命令中使用 --save-dev (npm) 和 --dev (Yarn) 选项的原因。

¥The Prisma CLI is typically installed locally as a development dependency, that's why the --save-dev (npm) and --dev (Yarn) options are used in the commands below.

npm

使用 npm 安装:

¥Install with npm:

npm install prisma --save-dev

Yarn

使用 yarn 安装:

¥Install with yarn:

yarn add prisma --dev

pnpm

使用 pnpm 安装:

¥Install with pnpm:

pnpm install prisma --save-dev

Bun

使用 Bun 安装:

¥Install with Bun:

bun add prisma

用法

¥Usage

如果你将 Prisma 作为开发依赖安装,则需要在包运行程序前添加 prisma 命令前缀。

¥If you installed Prisma as a development dependency, you need to prefix the prisma command with your package runner.

npm

npx prisma

Yarn

yarn prisma

pnpm

pnpm dlx prisma

Bun

bunx prisma

概要

¥Synopsis

安装后,可以从命令行调用 prisma 命令。当不带参数调用时,它将显示其命令用法和帮助文档:

¥The prisma command can be called from command line once installed. When called without arguments, it will display its command usage and help document:

prisma
Show CLI results
$ npx prisma

◭ Prisma is a modern DB toolkit to query, migrate and model your database (https://prisma.nodejs.cn)

Usage

$ prisma [command]

Commands

init Set up Prisma for your app
generate Generate artifacts (e.g. Prisma Client)
db Manage your database schema and lifecycle
migrate Migrate your database
studio Browse your data with Prisma Studio
validate Validate your Prisma schema
format Format your Prisma schema
version Displays Prisma version info
debug Displays Prisma debug info
mcp Starts an MCP server to use with AI development tools

Flags

--preview-feature Run Preview Prisma commands
--help, -h Show additional information about a command

Examples

Set up a new Prisma project
$ prisma init

Generate artifacts (e.g. Prisma Client)
$ prisma generate

Browse your data
$ prisma studio

Create migrations from your Prisma schema, apply them to the database, generate artifacts (e.g. Prisma Client)
$ prisma migrate dev

Pull the schema from an existing database, updating the Prisma schema
$ prisma db pull

Push the Prisma schema state to the database
$ prisma db push

Validate your Prisma schema
$ prisma validate

Format your Prisma schema
$ prisma format

Display Prisma version info
$ prisma version

Display Prisma debug info
$ prisma debug

你可以通过在命令后添加 --help 标志来获取有关任何 prisma 命令的其他帮助。

¥You can get additional help on any of the prisma commands by adding the --help flag after the command.

退出代码

¥Exit codes

所有 prisma CLI 命令在退出时都会返回以下代码:

¥All prisma CLI commands return the following codes when they exit:

  • 命令成功运行时退出代码 0

    ¥exit code 0 when a command runs successfully

  • 命令错误时退出代码 1

    ¥exit code 1 when a command errors

  • 当 CLI 收到信号中断 (SIGINT) 消息或用户取消提示时,退出代码 130。此退出代码在 Prisma ORM 版本 4.3.0 及更高版本中可用。

    ¥exit code 130 when the CLI receives a signal interrupt (SIGINT) message or if the user cancels a prompt. This exit code is available in Prisma ORM versions 4.3.0 and later.

遥测

¥Telemetry

遥测一词是指收集某些使用数据以帮助提高软件的质量。Prisma 在两种情况下使用遥测:

¥The term telemetry refers to the collection of certain usage data to help improve the quality of a piece of software. Prisma uses telemetry in two contexts:

  • 当它收集 CLI 使用数据时

    ¥when it collects CLI usage data

  • 当它提交 CLI 错误报告时

    ¥when it submits CLI error reports

本页面介绍了 Prisma 的整体遥测方法、收集的数据类型以及如何选择退出数据收集。

¥This page describes the overall telemetry approach for Prisma, what kind of data is collected and how to opt-out of data collection.

Prisma 为什么要收集指标?

¥Why does Prisma collect metrics?

遥测帮助我们更好地了解有多少用户正在使用我们的产品以及他们使用我们产品的频率。与许多遥测服务不同,我们的遥测实现有意限制范围,但实际上对开发者有用:

¥Telemetry helps us better understand how many users are using our products and how often they are using our products. Unlike many telemetry services, our telemetry implementation is intentionally limited in scope and is actually useful for the developer:

  • 范围有限:我们使用遥测技术来回答一个问题:有多少月度活跃开发者在使用 Prisma CLI?

    ¥Limited in scope: We use telemetry to answer one question: how many monthly active developers are using Prisma CLI?

  • 提供值:我们的遥测服务还会检查版本更新并提供安全通知。

    ¥Provides value: Our telemetry service also checks for version updates and offers security notices.

数据何时收集?

¥When is data collected?

数据在下面描述的两种情况下收集。

¥Data is collected in two scenarios that are described below.

使用数据

¥Usage data

调用 prisma CLI 和一般使用 Studio 会导致数据发送到 https://checkpoint.prisma.io 处的遥测服务器。注意:

¥Invocations of the prisma CLI and general usage of Studio results in data being sent to the telemetry server at https://checkpoint.prisma.io. Note that:

  • 数据不包括你的架构或数据库中的数据

    ¥The data does not include your schema or the data in your database

  • Prisma 仅在执行 CLI 命令后发送信息

    ¥Prisma only sends information after you execute a CLI command

以下是正在提交的数据的概述:

¥Here is an overview of the data that's being submitted:

字段属性描述
product字符串产品名称(例如 prisma
version字符串当前安装的产品版本(例如 1.0.0-rc0
arch字符串客户端的操作系统架构(例如 amd64)。
os字符串客户端的操作系统(例如 darwin)。
node_version字符串客户端的节点版本(例如 v12.12.0)。
signature字符串随机、不可识别的签名 UUID(例如 91b014df3-9dda-4a27-a8a7-15474fd899f8
user_agent字符串检查点客户端的用户代理(例如 prisma/js-checkpoint
timestamp字符串当请求以 RFC3339 格式发送时(例如 2019-12-12T17:45:56Z

你可以通过将 CHECKPOINT_DISABLE 环境变量设置为 1 来选择退出此行为,例如:

¥You can opt-out of this behavior by setting the CHECKPOINT_DISABLE environment variable to 1, e.g.:

export CHECKPOINT_DISABLE=1

错误报告

¥Error reporting

当 CLI 发生崩溃时,Prisma 可能会收集错误数据。

¥Prisma potentially collects error data when there is a crash in the CLI.

在提交错误报告之前,总会有提示要求你确认或拒绝提交错误报告!未经你明确同意,绝不会提交错误报告!

¥Before an error report is submitted, there will always be a prompt asking you to confirm or deny the submission of the error report! Error reports are never submitted without your explicit consent!

如何选择退出数据收集?

¥How to opt-out of data collection?

使用数据

¥Usage data

你可以通过将 CHECKPOINT_DISABLE 环境变量设置为 1 来选择退出使用数据收集,例如:

¥You can opt-out of usage data collection by setting the CHECKPOINT_DISABLE environment variable to 1, e.g.:

export CHECKPOINT_DISABLE=1

错误报告

¥Error reporting

你可以通过在交互式提示中回答“否”来选择退出数据收集。

¥You can opt-out of data collection by responding to the interactive prompt with no.