Skip to main content

Vercel

Vercel Marketplace 与 Prisma Postgres 的集成 将你的 Vercel 项目与 Prisma Postgres 实例连接起来。连接后,集成将自动在你部署的 Vercel 应用上设置 DATABASE_URL 环境变量。

¥The Vercel Marketplace integration for Prisma Postgres connects your Vercel projects with Prisma Postgres instances. Once connected, the integration will automatically set the DATABASE_URL environment variable on your deployed Vercel app.

特性

¥Features

  • 无需离开 Vercel 仪表板即可创建并使用 Prisma Postgres 实例。

    ¥Create and use Prisma Postgres instances without leaving the Vercel dashboard.

  • 为生产环境和预览环境自动生成 Prisma Postgres URL 密钥。

    ¥Automatic generation of Prisma Postgres URLs keys for production and preview environments.

  • 简化 Vercel 项目的环境配置。

    ¥Simplified environment configuration for your Vercel project.

  • 用于升级/降级 Prisma Postgres 定价方案的计费工作流程。

    ¥Billing workflows to up-/ and downgrade your Prisma Postgres pricing plan.

  • 已准备好部署带身份验证的全栈 Next.js template

    ¥Ready-to-deploy fullstack Next.js template with authentication.

用法

¥Usage

注意:使用 Prisma Postgres 扩展的最简单方法是通过 Next.js 身份验证模板

¥Note: The easiest way to use the Prisma Postgres extension is via the Next.js Auth Template.

安装扩展

¥Install the extension

要安装扩展程序,请点击 Prisma Postgres 集成页面 顶部的“安装”。

¥To install the extension, click Install at the top of the Prisma Postgres integration page.

集成现在将显示在你的集成列表中,例如 https://vercel.com/<VERCEL-TEAM>/~/integrations

¥The integration will now show up on your list of integrations, e.g. https://vercel.com/<VERCEL-TEAM>/~/integrations.

创建一个新数据库

¥Create a new database

安装完成后,你可以导航到“存储”选项卡并点击“创建数据库”。

¥Once installed, you can navigate to the Storage tab and click Create Database.

选择 Prisma Postgres 并点击“继续”。然后选择数据库的区域和定价方案,并再次点击“继续”。

¥Select Prisma Postgres and click Continue. Then select the Region for the database and a Pricing Plan, and click Continue again.

最后,为数据库命名并点击“创建”。

¥Finally, give the database a Name and click Create.

数据库现已准备就绪,可以连接到你的 Vercel 项目。

¥The database is now ready and can be connected to your Vercel projects.

将数据库连接到 Vercel 项目

¥Connect database to Vercel project

在你的 Vercel 项目中,你现在可以点击“存储”选项卡,选择刚刚创建的数据库,然后点击“连接”。这将自动在该项目中设置 DATABASE_URL 环境变量,并使你的应用能够访问新创建的 Prisma Postgres 实例。

¥In your Vercel project, you can now click the Storage tab, select the database you just created and then click Connect. This will automatically set the DATABASE_URL environment variable in that project and enable your application to access your newly created Prisma Postgres instance.

在 Prisma Studio 中查看和编辑数据

¥Viewing and editing data in Prisma Studio

要查看和编辑 Prisma Postgres 实例中的数据,你可以使用 Prisma 工作室 的本地版本。

¥To view and edit the data in your Prisma Postgres instance, you can use the local version of Prisma Studio.

在你设置了 DATABASE_URL 的本地项目版本中,运行以下命令打开 Prisma Studio:

¥In the local version of your project where you have your DATABASE_URL set, run the following command to open Prisma Studio:

npx prisma studio

其他注意事项

¥Additional considerations

确保你的项目使用 DATABASE_URL 环境变量

¥Ensure your project uses the DATABASE_URL environment variable

确保 schema.prisma 文件中的数据源已配置为使用 DATABASE_URL 环境变量:

¥Ensure that the data source in your schema.prisma file is configured to use the DATABASE_URL environment variable:

// schema.prisma
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

package.json 中使用 postinstall 脚本生成 Prisma 客户端

¥Generate Prisma Client in a postinstall script in package.json

为确保生成的 Prisma 客户端库在已部署的 Vercel 项目中可用,你应该将 postinstall 脚本添加到 package.json 文件的 scripts 部分:

¥To ensure the generated Prisma Client library is available on your deployed Vercel project, you should add a postinstall script to the scripts section of your package.json file:

package.json
{
// ...
"scripts": {
// ...
"postinstall": "prisma generate --no-engine"
}
//
}

--no-engine 标志确保查询引擎二进制文件不包含在生成的 Prisma 客户端库中。使用 Prisma Postgres 时不需要它。

¥The --no-engine flag ensures that the query engine binary is kept out of the generated Prisma Client library. It's not needed when using Prisma Postgres.

示例:使用 Prisma Postgres 部署 Next.js 模板

¥Example: Deploy a Next.js template with Prisma Postgres

首先,你可以部署我们的 Next.js 入门模板,并在部署流程中通过 Prisma Postgres 实例进行连接。

¥To get started you can deploy our Next.js starter template and connect via Prisma Postgres instance during the deployment flow.