部署到 Sevalla
本指南介绍如何将使用 Prisma ORM 和 PostgreSQL 的 Node.js 服务器部署到 Sevalla。该应用公开 REST API 并使用 Prisma 客户端查询 PostgreSQL 数据库。应用和数据库都将托管在 Sevalla 上。
¥This guide explains how to deploy a Node.js server that uses Prisma ORM and PostgreSQL to Sevalla. The app exposes a REST API and uses Prisma Client to query a PostgreSQL database. Both the app and database will be hosted on Sevalla.
Sevalla 是一个以开发者为中心的 PaaS 平台,旨在简化应用和服务器部署。你可以轻松托管你的应用、数据库、对象存储和静态站点。
¥Sevalla is a developer-focused PaaS platform designed to simplify application and server deployment. You can easily host your applications, databases, object storage and static sites.
它支持基于 Git 的部署、Dockerfile 和 Procfile,并在 Google Kubernetes Engine 上运行,并通过 Cloudflare 进行全球交付。
¥It supports Git-based deployments, Dockerfiles, and Procfiles and runs on Google Kubernetes Engine with global delivery via Cloudflare.
对于此示例,了解以下内容很有帮助:
¥For this example, it's helpful to know:
-
Sevalla 支持长期运行的“serverful”应用,并具有内置的自动扩缩功能和灵活的 Pod 大小。
¥Sevalla supports long-running “serverful” applications with built-in autoscaling and flexible pod sizes.
-
基于 Git 的部署与 GitHub、GitLab 和 Bitbucket 集成。
¥Git-based deployments are integrated with GitHub, GitLab, and Bitbucket.
-
原生支持 PostgreSQL、MySQL、MariaDB、Redis 和 Valkey 数据库。
¥PostgreSQL, MySQL, MariaDB, Redis, and Valkey databases are natively supported.
-
应用和数据库可以通过私有网络安全地连接,并具有自动环境变量注入功能。
¥Applications and databases can be securely connected through private networking with automatic environment variable injection.
先决条件
¥Prerequisites
要开始使用 Prisma,你只需要:
¥To get started, all you need is:
-
Sevalla 账户(附带 50 美元免费积分)
¥A Sevalla account (comes with $50 in free credits)
-
包含你的应用代码的 GitHub 存储库。
¥A GitHub repository with your application code.
注意:如果你尚未准备好项目,可以使用我们的 Prisma 项目示例。这是一个简单的 Express.js 应用,它使用 Prisma ORM,包含一个 REST API、一个用于测试端点的前端、一个已定义的带有迁移的 Prisma 模式以及一个可选的数据库播种脚本。
¥Note: If you don't have a project ready, you can use our example Prisma project. It's a simple Express.js application that uses Prisma ORM and includes a REST API, a frontend for testing endpoints, a defined Prisma schema with migrations, and an optional database seeding script.
在 Sevalla 上创建应用
¥Create an app on Sevalla
首先,在 Sevalla 仪表板上创建一个新的应用。点击侧边栏上的“应用”,然后点击“创建应用”按钮,如下所示。
¥First, create a new application on your Sevalla dashboard. Click Applications on the sidebar and then click the Create an app button, as shown below.
接下来,选择你的 Git 存储库。Sevalla 支持从私有和公共仓库部署。如果你正在使用我们的示例项目,则无需 fork - 只需输入 URL https://github.com/sevalla-templates/express-prisma-demo
即可。
¥Next, select your Git repository. Sevalla supports deploying from both private and public repositories. If you're using our example project, there's no need to fork — simply enter the URL https://github.com/sevalla-templates/express-prisma-demo
.
选择合适的分支(通常为 main
或 master
),设置应用名称,选择所需的部署区域,并选择 Pod 大小。(你可以使用免费积分以 0.5 CPU / 1GB RAM 开始)
¥Choose the appropriate branch (usually main
or master
), set your application's name, select the desired deployment region, and pick your pod size. (You can start with 0.5 CPU / 1GB RAM using your free credits)
点击“创建”,但暂时跳过部署步骤,这样由于我们尚未添加数据库,因此不会失败。
¥Click Create, but skip the deploy step for now, so it does not fail since we have not added the database.
在 Sevalla 上设置数据库
¥Set up the database on Sevalla
在你的 Sevalla 仪表板上,点击“数据库”>“添加数据库”。选择 PostgreSQL(或你首选的配置数据库类型),然后提供数据库名称、用户名和密码,或者直接使用默认生成的详细信息。
¥On your Sevalla dashboard, click Databases > Add database. Select PostgreSQL (or your preferred configured database type), and then provide a database name, username, and password, or simply use the default generated details.
接下来,为数据库指定一个可识别的名称,以便在 Sevalla 仪表板中轻松识别。确保选择与应用相同的区域,选择合适的数据库大小,然后单击“创建”。
¥Next, give the database a recognizable name for easy identification within your Sevalla dashboard. Ensure you select the same region as your application, choose an appropriate database size, and click Create.
创建数据库后,向下滚动到“已连接的应用”部分,然后单击“添加连接”。
¥Once your database has been created, scroll down to the Connected Applications section and click Add Connection.
选择你之前创建的应用并启用 "添加环境变量"。确保变量名称设置为 DATABASE_URL
(如果默认为 DB_URL
,请相应地更改)。
¥Select the application you created previously and enable "Add environment variables". Make sure the variable name is set to DATABASE_URL
(if it defaults to DB_URL
, change it accordingly).
最后,点击“添加连接”。这将安全地将你的应用链接到数据库,并配置必要的环境变量。
¥Finally, click Add connection. This securely links your application to your database and configures the necessary environment variable.
触发部署
¥Trigger deployment
现在你的应用和数据库已连接,请返回应用的“部署”选项卡并点击“部署”。
¥Now that your application and database are connected, return to your application's Deployment tab and click Deploy.
注意:Sevalla 使用 Nixpacks 自动构建你的应用,并检测你项目的
package.json
和start
脚本。如果你更愿意使用 Dockerfile 或 Buildpacks,请导航至“设置”>“构建”,然后点击“构建环境”部分下的“更新设置”以自定义构建方法。¥Note: Sevalla automatically builds your application using Nixpacks, detecting your project's
package.json
andstart
script. If you'd rather use a Dockerfile or Buildpacks, navigate to Settings > Build, and click Update Settings under the Build environment section to customize your build method.
填充数据库(可选)
¥Seed the database (optional)
如果你的项目包含种子脚本(通常位于 prisma/seed.js
),你可以在部署应用后使用初始数据或演示数据填充数据库。
¥If your project includes a seed script (typically located at prisma/seed.js
), you can populate your database with initial or demo data after deploying your application.
为此,请导航到应用的 Web 终端(在“应用”>“[你的应用]”>“Web 终端”下)并运行以下命令:
¥To do this, navigate to your application's Web Terminal (under Applications > [Your App] > Web Terminal) and run the following command:
npx prisma db seed
Web 终端如下所示:
¥This is what the web terminal looks like:
完成后,你可以通过 Sevalla 内置的交互式工作室直接管理和与数据库交互。如下所示,我们可以看到已播种的数据:
¥Once this is done, you can manage and interact with your database directly via Sevalla's built-in interactive studio. As shown below, we can see the seeded data:
恭喜!你已成功使用 Prisma ORM 将 Node.js 应用部署到 Sevalla。你的应用和数据库现已连接、安全且可投入生产!
¥Congratulations! You've successfully deployed a Node.js application using Prisma ORM to Sevalla. Your app and database are now connected, secure, and production-ready!