部署
本节介绍如何将使用 Prisma Client 和 TypeScript 的 Node.js 应用部署到各种平台。
¥This section describes how to deploy Node.js applications that use Prisma Client and TypeScript to various platforms.
如果 Prisma ORM 的 Rust 引擎二进制文件导致包体积过大、构建速度缓慢或部署问题(例如,在无服务器或边缘环境中),你可以使用 generator
块的以下配置来使用它,而无需使用它们:
¥If Prisma ORM's Rust engine binaries cause large bundle sizes, slow builds, or deployment issues (for example, in serverless or edge environments), you can use it without them using this configuration of your generator
block:
generator client {
provider = "prisma-client-js" // or "prisma-client"
engineType = "client"
}
自 v6.16.0 以来,不带 Rust 二进制文件的 Prisma ORM 一直是 一般可用。
¥Prisma ORM without Rust binaries has been Generally Available since v6.16.0.
请注意,在这种情况下,你需要使用 驱动适配器。
¥Note that you need to use a driver adapter in this case.
使用此架构时:
¥When using this architecture:
-
无需下载或安装 Rust 查询引擎二进制文件。
¥No Rust query engine binary is downloaded or shipped.
-
数据库连接池由你安装的原生 JS 数据库驱动程序(例如,PostgreSQL 的
@prisma/adapter-pg
)维护。¥The database connection pool is maintained by the native JS database driver you install (e.g.,
@prisma/adapter-pg
for PostgreSQL).
此设置可以简化以下环境中的部署:
¥This setup can simplify deployments in:
-
无服务器函数
¥Serverless functions
-
Edge 运行时
¥Edge runtimes
-
只读文件系统环境
¥Read-only filesystem environments
-
具有严格大小限制的 CI/CD 流水线
¥CI/CD pipelines with strict size limits
在 文档在这里 中了解更多信息。
¥Learn more in the docs here.
好奇我们为什么放弃 Rust 引擎?了解为什么我们在 博客文章 中从 Rust 二进制引擎过渡到全 TypeScript 方法,以实现更快、更轻量的 Prisma ORM。
¥Curious why we moved away from the Rust engine? Take a look at why we transitioned from Rust binary engines to an all-TypeScript approach for a faster, lighter Prisma ORM in this blog post.
在这个部分
¥In this section
部署 Prisma ORM
使用 Prisma Client 的项目可以部署到许多不同的云平台。鉴于云平台的多样性和不同的名称,值得注意的是不同的部署范例,因为它们会影响你使用 Prisma Client 部署应用的方式。
传统服务器
无服务器函数
边缘函数
模块打包器
概述
部署数据库更改
要将待处理的迁移应用到暂存、测试或生产环境,请在 CI/CD 管道中运行 migrate deploy 命令:
从本地环境部署迁移
在两种情况下,你可能会考虑将迁移直接从本地环境部署到生产环境。
部署到 AWS 平台时的注意事项
下面介绍了部署到不同 AWS 平台时你可能会遇到的一些注意事项。
部署到不同的操作系统
Prisma 客户端依赖于与你的应用在同一主机上作为二进制文件运行的 查询引擎。