Skip to main content

如何使用 GitHub Actions 和 Prisma Postgres 配置预览数据库

15 min

概述

¥Overview

本指南向你展示如何使用 GitHub Actions 和 Prisma Postgres 管理 API 自动创建和删除 Prisma Postgres 数据库。该设置会为每个拉取请求提供一个新数据库,并使用示例数据进行种子填充,github-actions 机器人会留下包含数据库名称和状态的评论。

¥This guide shows you how to automatically create and delete Prisma Postgres databases using GitHub Actions and the Prisma Postgres management API. The setup provisions a new database for every pull request, seeds it with sample data, and the github-actions bot leaves a comment with the database name and the status.

GitHub Actions comment

PR 关闭后,数据库将自动删除。这允许你单独测试更改,而不会影响主开发数据库。

¥After the PR is closed, the database is automatically deleted. This allows you to test changes in isolation without affecting the main development database.

先决条件

¥Prerequisites

请确保你已具备以下条件:

¥Make sure you have the following:

  • Node.js 18 或更高版本

    ¥Node.js 18 or later

  • 账户

    ¥A account

  • GitHub 仓库

    ¥GitHub repository

1. 设置你的项目

¥ Set up your project

初始化项目:

¥Initialize your project:

mkdir prisma-gha-demo && cd prisma-gha-demo
npm init -y

2. 安装和配置 Prisma

¥ Install and configure Prisma

在本部分中,你将在项目中设置 Prisma,并在将其集成到 GitHub Actions 之前验证其在本地是否正常工作。这涉及安装 Prisma 的依赖、连接到 Prisma Postgres 数据库、定义数据模型、应用模式以及使用示例数据填充数据库。

¥In this section, you'll set up Prisma in your project and verify that it works locally before integrating it into GitHub Actions. This involves installing Prisma's dependencies, connecting to a Prisma Postgres database, defining your data models, applying your schema, and seeding the database with sample data.

完成本节后,你的项目将完全准备好在本地和 CI 工作流中使用 Prisma。

¥By the end of this section, your project will be fully prepared to use Prisma both locally and in a CI workflow.

2.1.安装依赖

¥2.1. Install dependencies

要开始使用 Prisma,请安装所需的依赖:

¥To get started with Prisma, install the required dependencies:

npm install @prisma/extension-accelerate @prisma/client

安装开发依赖:

¥Install the development dependencies:

npm install prisma tsx dotenv --save-dev

安装后,初始化 Prisma:

¥Once installed, initialize Prisma:

npx prisma init --db --output ../src/generated/prisma

这创建:

¥This creates:

  • 包含 schema.prismaprisma/ 目录

    ¥A prisma/ directory with schema.prisma

  • 包含 DATABASE_URL.env 文件

    ¥A .env file with DATABASE_URL

  • src/generated/prisma 中生成的客户端

    ¥A generated client in src/generated/prisma

2.2.定义 Prisma 模式

¥2.2. Define your Prisma schema

prisma/schema.prisma 编辑为:

¥Edit prisma/schema.prisma to:

prisma/schema.prisma
generator client {
provider = "prisma-client"
output = "../src/generated/prisma"
}

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

model User {
id Int @id @default(autoincrement())
email String @unique
name String?
posts Post[]
}

model Post {
id Int @id @default(autoincrement())
title String
content String?
published Boolean @default(false)
authorId Int
author User @relation(fields: [authorId], references: [id])
}

2.3.运行初始迁移并生成客户端

¥2.3. Run initial migration and generate client

npx prisma migrate dev --name init

这将推送你的架构并准备客户端。

¥This pushes your schema and prepares the client.

2.4.种子数据库

¥2.4. Seed the database

src/seed.ts 处创建一个文件:

¥Create a file at src/seed.ts:

src/seed.ts
import { withAccelerate } from "@prisma/extension-accelerate";
import { PrismaClient } from "../src/generated/prisma/client";
import "dotenv/config";

const prisma = new PrismaClient().$extends(withAccelerate());

const userData = [
{
name: "Alice",
email: "alice@prisma.io",
posts: {
create: [
{
title: "Join the Prisma Discord",
content: "https://pris.ly/discord",
published: true,
},
{
title: "Prisma on YouTube",
content: "https://pris.ly/youtube",
},
],
},
},
{
name: "Bob",
email: "bob@prisma.io",
posts: {
create: [
{
title: "Follow Prisma on Twitter",
content: "https://twitter.com/prisma",
published: true,
},
],
},
},
];

export async function main() {
for (const u of userData) {
await prisma.user.create({ data: u });
}
}

main()
.catch(console.error)
.finally(() => prisma.$disconnect());

更新你的 package.json

¥Update your package.json:

package.json
{
{
"name": "prisma-gha-demo",
"version": "1.0.0",
"description": "",
"scripts": {
"seed": "tsx src/seed.ts"
},
// other configurations...
}

然后运行:

¥Then run:

npm run seed
npx prisma studio

导航到 http://localhost:5555 并验证数据库是否已填充示例数据。现在你已准备好使用 GitHub Actions 自动化此过程。

¥Navigate to http://localhost:5555 and verify that the database has been seeded with sample data. Now you're ready to automate this process with GitHub Actions.

3. 添加 GitHub Actions 工作流

¥ Add the GitHub Actions workflow

在此步骤中,你将设置一个 GitHub Actions 工作流,该工作流会在新的拉取请求 (PR) 打开时自动配置 Prisma Postgres 数据库。PR 关闭后,工作流将清理数据库。

¥In this step, you will set up a GitHub Actions workflow that automatically provisions a Prisma Postgres database when a new pull request (PR) is opened. Once the PR is closed, the workflow will clean up the database.

3.1 创建工作流文件

¥3.1 Create the workflow file

首先创建所需的目录和文件:

¥Start by creating the required directory and file:

mkdir -p .github/workflows
touch .github/workflows/prisma-postgres-management.yml

此文件将包含按 PR 管理数据库的逻辑。此 GitHub Actions 工作流程:

¥This file will contain the logic to manage databases on a per-PR basis. This GitHub Actions workflow:

  • 在提交 PR 时配置临时的 Prisma Postgres 数据库

    ¥Provisions a temporary Prisma Postgres database when a PR is opened

  • 使用测试数据填充数据库

    ¥Seeds the database with test data

  • PR 关闭时清理数据库

    ¥Cleans up the database when the PR is closed

  • 支持手动执行配置和清理

    ¥Supports manual execution for both provisioning and cleanup

注意

此工作流使用 us-east-1 作为 Prisma Postgres 的默认区域。你可以通过修改 API 调用中的 region 参数,甚至通过在工作流中添加 region 输入,将其更改为你首选的区域。

¥This workflow uses us-east-1 as the default region for Prisma Postgres. You can change this to your preferred region by modifying the region parameter in the API calls, or even by adding a region input to the workflow.

3.2.添加基本配置

¥3.2. Add the base configuration

将以下内容粘贴到 .github/workflows/prisma-postgres-management.yml 中。这将在工作流运行时进行设置并提供所需的环境变量。

¥Paste the following into .github/workflows/prisma-postgres-management.yml. This sets up when the workflow runs and provides required environment variables.

.github/workflows/prisma-postgres-management.yml
name: Prisma Postgres Management API Workflow

on:
pull_request:
types: [opened, reopened, closed]
workflow_dispatch:
inputs:
action:
description: "Action to perform"
required: true
default: "provision"
type: choice
options:
- provision
- cleanup
database_name:
description: "Database name (for testing, will be sanitized)"
required: false
type: string

env:
PRISMA_POSTGRES_SERVICE_TOKEN: ${{ secrets.PRISMA_POSTGRES_SERVICE_TOKEN }}
PRISMA_PROJECT_ID: ${{ secrets.PRISMA_PROJECT_ID }}
# Sanitize database name once at workflow level
DB_NAME: ${{ github.event.pull_request.number != null && format('pr-{0}-{1}', github.event.pull_request.number, github.event.pull_request.head.ref) || (inputs.database_name != '' && inputs.database_name || format('test-{0}', github.run_number)) }}

# Prevent concurrent runs of the same PR
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

现在你将向此工作流中添加预配和清理作业。这些作业将根据拉取请求事件处理 Prisma Postgres 数据库的创建和删除。

¥Now you will be adding the provision and cleanup jobs to this workflow. These jobs will handle the creation and deletion of Prisma Postgres databases based on the pull request events.

3.3.向工作流添加配置作业

¥3.3. Add a provision job to the workflow

现在添加一个作业,用于在 PR 提交或手动触发时预配数据库。配置作业:

¥Now add a job to provision the database when the PR is opened or when triggered manually. The provision job:

  • 安装依赖

    ¥Installs dependencies

  • 检查现有数据库

    ¥Checks for existing databases

  • 如有需要,创建一个新的

    ¥Creates a new one if needed

  • 种子数据库

    ¥Seeds the database

  • PR 状态为

    ¥Comments on the PR with status

将以下内容附加到你的工作流文件中的 jobs: 键下:

¥Append the following under the jobs: key in your workflow file:

.github/workflows/prisma-postgres-management.yml
jobs:
provision-database:
if: (github.event_name == 'pull_request' && github.event.action != 'closed') || (github.event_name == 'workflow_dispatch' && inputs.action == 'provision')
runs-on: ubuntu-latest
permissions: write-all
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
cache: "npm"

- name: Install Dependencies
run: npm install

- name: Validate Environment Variables
run: |
if [ -z "${{ env.PRISMA_POSTGRES_SERVICE_TOKEN }}" ]; then
echo "Error: PRISMA_POSTGRES_SERVICE_TOKEN secret is not set"
exit 1
fi
if [ -z "${{ env.PRISMA_PROJECT_ID }}" ]; then
echo "Error: PRISMA_PROJECT_ID secret is not set"
exit 1
fi

- name: Sanitize Database Name
run: |
# Sanitize the database name to match Prisma's requirements
DB_NAME="$(echo "${{ env.DB_NAME }}" | tr '/' '_' | tr '-' '_' | tr '[:upper:]' '[:lower:]')"
echo "DB_NAME=$DB_NAME" >> $GITHUB_ENV

- name: Check If Database Exists
id: check-db
run: |
echo "Fetching all databases..."
RESPONSE=$(curl -s -X GET \
-H "Authorization: Bearer ${{ env.PRISMA_POSTGRES_SERVICE_TOKEN }}" \
-H "Content-Type: application/json" \
"https://api.prisma.io/v1/projects/${{ env.PRISMA_PROJECT_ID }}/databases")

echo "Looking for database with name: ${{ env.DB_NAME }}"

# Extract database ID using jq to properly parse JSON
DB_EXISTS=$(echo "$RESPONSE" | jq -r ".data[]? | select(.name == \"${{ env.DB_NAME }}\") | .id")

if [ ! -z "$DB_EXISTS" ] && [ "$DB_EXISTS" != "null" ]; then
echo "Database ${{ env.DB_NAME }} exists with ID: $DB_EXISTS."
echo "exists=true" >> $GITHUB_OUTPUT
echo "db-id=$DB_EXISTS" >> $GITHUB_OUTPUT
else
echo "No existing database found with name ${{ env.DB_NAME }}"
echo "exists=false" >> $GITHUB_OUTPUT
fi

- name: Create Database
id: create-db
if: steps.check-db.outputs.exists != 'true'
run: |
echo "Creating database ${{ env.DB_NAME }}..."
RESPONSE=$(curl -s -X POST \
-H "Authorization: Bearer ${{ env.PRISMA_POSTGRES_SERVICE_TOKEN }}" \
-H "Content-Type: application/json" \
-d "{\"name\": \"${{ env.DB_NAME }}\", \"region\": \"us-east-1\"}" \
"https://api.prisma.io/v1/projects/${{ env.PRISMA_PROJECT_ID }}/databases")

# Check if response contains an id (success case)
if echo "$RESPONSE" | grep -q '"id":'; then
echo "Database created successfully"
CONNECTION_STRING=$(echo "$RESPONSE" | jq -r '.data.connectionString')
echo "connection-string=$CONNECTION_STRING" >> $GITHUB_OUTPUT
else
echo "Failed to create database"
echo "$RESPONSE"
exit 1
fi

- name: Get Connection String for Existing Database
id: get-connection
if: steps.check-db.outputs.exists == 'true'
run: |
echo "Creating new connection string for existing database..."
CONNECTION_RESPONSE=$(curl -s -X POST \
-H "Authorization: Bearer ${{ env.PRISMA_POSTGRES_SERVICE_TOKEN }}" \
-H "Content-Type: application/json" \
-d '{"name":"read_write_key"}' \
"https://api.prisma.io/v1/databases/${{ steps.check-db.outputs.db-id }}/connections")

CONNECTION_STRING=$(echo "$CONNECTION_RESPONSE" | jq -r '.data.connectionString')
echo "connection-string=$CONNECTION_STRING" >> $GITHUB_OUTPUT

- name: Setup Database Schema
run: |
# Get connection string from appropriate step
if [ "${{ steps.check-db.outputs.exists }}" = "true" ]; then
CONNECTION_STRING="${{ steps.get-connection.outputs.connection-string }}"
else
CONNECTION_STRING="${{ steps.create-db.outputs.connection-string }}"
fi

# Set the DATABASE_URL
export DATABASE_URL="$CONNECTION_STRING"

# Generate Prisma Client
npx prisma generate

# Push schema to database
npx prisma db push

- name: Seed Database
run: |
# Get connection string from appropriate step
if [ "${{ steps.check-db.outputs.exists }}" = "true" ]; then
CONNECTION_STRING="${{ steps.get-connection.outputs.connection-string }}"
else
CONNECTION_STRING="${{ steps.create-db.outputs.connection-string }}"
fi

# Set the DATABASE_URL environment variable for the seed script
export DATABASE_URL="$CONNECTION_STRING"

# Generate Prisma Client
npx prisma generate

# Run the seed script
npm run seed

- name: Comment PR
if: success() && github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `🗄️ Database provisioned successfully!\n\nDatabase name: ${{ env.DB_NAME }}\nStatus: Ready and seeded with sample data`
})

- name: Output Database Info
if: success() && github.event_name == 'workflow_dispatch'
run: |
echo "🗄️ Database provisioned successfully!"
echo "Database name: ${{ env.DB_NAME }}"
echo "Status: Ready and seeded with sample data"

3.4.向工作流添加清理作业

¥3.4. Add a cleanup job to the workflow

拉取请求关闭后,你可以通过添加清理作业来自动删除关联的数据库。清理作业:

¥When a pull request is closed, you can automatically remove the associated database by adding a cleanup job. The cleanup job:

  • 通过名称查找数据库

    ¥Finds the database by name

  • 将其从 Prisma Postgres 项目中删除

    ¥Deletes it from the Prisma Postgres project

  • 也可以使用 action: cleanup 手动触发

    ¥Can also be triggered manually with action: cleanup

将以下内容附加到你的 jobs: 部分,provision-database 作业之后:

¥Append the following to your jobs: section, after the provision-database job:

.github/workflows/prisma-postgres-management.yml
  cleanup-database:
if: (github.event_name == 'pull_request' && github.event.action == 'closed') || (github.event_name == 'workflow_dispatch' && inputs.action == 'cleanup')
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Validate Environment Variables
run: |
if [ -z "${{ env.PRISMA_POSTGRES_SERVICE_TOKEN }}" ]; then
echo "Error: PRISMA_POSTGRES_SERVICE_TOKEN secret is not set"
exit 1
fi
if [ -z "${{ env.PRISMA_PROJECT_ID }}" ]; then
echo "Error: PRISMA_PROJECT_ID secret is not set"
exit 1
fi

- name: Sanitize Database Name
run: |
# Sanitize the database name
DB_NAME="$(echo "${{ env.DB_NAME }}" | tr '/' '_' | tr '-' '_' | tr '[:upper:]' '[:lower:]')"
echo "DB_NAME=$DB_NAME" >> $GITHUB_ENV

- name: Delete Database
run: |
echo "Fetching all databases..."
RESPONSE=$(curl -s -X GET \
-H "Authorization: Bearer ${{ env.PRISMA_POSTGRES_SERVICE_TOKEN }}" \
-H "Content-Type: application/json" \
"https://api.prisma.io/v1/projects/${{ env.PRISMA_PROJECT_ID }}/databases")

echo "Looking for database with name: ${{ env.DB_NAME }}"

# Extract database ID using jq to properly parse JSON
DB_EXISTS=$(echo "$RESPONSE" | jq -r ".data[]? | select(.name == \"${{ env.DB_NAME }}\") | .id")

if [ ! -z "$DB_EXISTS" ] && [ "$DB_EXISTS" != "null" ]; then
echo "Database ${{ env.DB_NAME }} exists with ID: $DB_EXISTS. Deleting..."
DELETE_RESPONSE=$(curl -s -X DELETE \
-H "Authorization: Bearer ${{ env.PRISMA_POSTGRES_SERVICE_TOKEN }}" \
-H "Content-Type: application/json" \
"https://api.prisma.io/v1/databases/$DB_EXISTS")

echo "Delete API Response: $DELETE_RESPONSE"

if echo "$DELETE_RESPONSE" | grep -q '"error":'; then
ERROR_MSG=$(echo "$DELETE_RESPONSE" | jq -r '.message // "Unknown error"')
echo "Failed to delete database: $ERROR_MSG"
exit 1
else
echo "Database deletion initiated successfully"
fi
else
echo "No existing database found with name ${{ env.DB_NAME }}"
fi

此操作完成了 Prisma Postgres 管理工作流程的设置。在下一步中,你将配置所需的 GitHub secrets 以使用 Prisma API 进行身份验证。

¥This completes your Prisma Postgres management workflow setup. In the next step, you'll configure the required GitHub secrets to authenticate with the Prisma API.

4. 将代码存储在 GitHub 中

¥ Store the code in GitHub

初始化 Git 仓库并推送至 GitHub

¥Initialize a git repository and push to GitHub:

如果你在 GitHub 中还没有代码库,在 GitHub 上创建一个。存储库准备就绪后,运行以下命令:

¥If you don't have a repository in GitHub yet, create one on GitHub. Once the repository is ready, run the following commands:

git add .
git commit -m "Initial commit with Prisma Postgres integration"
git branch -M main
git remote add origin https://github.com/<your-username>/<repository-name>.git
git push -u origin main
注意

<your-username><repository-name> 替换为你的 GitHub 用户名和仓库名称。

¥Replace <your-username> and <repository-name> with your GitHub username and the name of your repository.

5. 检索工作流的密钥

¥ Retrieve the secrets for the workflow

5.1.检索你的 Prisma Postgres 服务令牌

¥5.1. Retrieve your Prisma Postgres service token

要管理 Prisma Postgres 数据库,你还需要一个服务令牌。按照以下步骤获取:

¥To manage Prisma Postgres databases, you also need a service token. Follow these steps to retrieve it:

  1. 确保你位于上一步创建项目所在的工作区中。

    ¥Make sure you are in the same workspace where you created your project in the last step.

  2. 点击左侧边栏中的“集成”。

    ¥Click on Integrations in the left sidebar.

  3. 点击“新建服务令牌”按钮。

    ¥Click on New service token button.

  4. 在弹出窗口中,在“令牌名称”字段中输入一个描述性名称。

    ¥In the popup, enter a descriptive name in the Token name field.

  5. 点击“创建服务令牌”按钮。

    ¥Click the Create service token button.

  6. 复制生成的令牌并将其作为 PRISMA_POSTGRES_SERVICE_TOKEN 保存在你的 .env 文件中。此令牌是下一步脚本所必需的,并且还必须添加到你的 GitHub Actions 密钥中。

    ¥Copy the generated token and save it in your .env file as PRISMA_POSTGRES_SERVICE_TOKEN. This token is required for the next step's script and must also be added to your GitHub Actions secrets.

5.2 获取要配置 Prisma Postgres 数据库的项目 ID

¥5.2 Retrieve the project ID where you want to provision Prisma Postgres databases

为了避免与你的开发数据库发生冲突,你现在将专门为 CI 工作流创建一个专用项目。使用以下 curl 命令,通过 Prisma Postgres Management API 创建一个新的 Prisma Postgres 项目:

¥To avoid conflicts with your development databases, you'll now create a dedicated project specifically for CI workflows. Use the following curl command to create a new Prisma Postgres project using the Prisma Postgres Management API:

curl -X POST https://api.prisma.io/v1/projects \
-H "Authorization: Bearer $PRISMA_POSTGRES_SERVICE_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"region\": \"us-east-1\", \"name\": \"$PROJECT_NAME\"}"
注意

确保将 $PRISMA_POSTGRES_SERVICE_TOKEN 变量替换为你之前存储的服务令牌。

¥Make sure to replace the $PRISMA_POSTGRES_SERVICE_TOKEN variable with the service token you stored earlier.

将 $PRISMA_POSTGRES_SERVICE_TOKEN 替换为服务令牌,并将 $PROJECT_NAME 替换为你的项目名称(例如 my-gha-preview)。该脚本将在 us-east-1 区域创建一个新的 Prisma Postgres 项目。

¥Replace the $PRISMA_POSTGRES_SERVICE_TOKEN with the service token and the $PROJECT_NAME with a name for your project (e.g., my-gha-preview). The script will create a new Prisma Postgres project in the us-east-1 region.

CLI 的输出将如下所示:

¥The CLI output will then look like this:

{
"data": {
"id": "$PRISMA_PROJECT_ID",
"type": "project",
"name": "$PROJECT_NAME",
"createdAt": "2025-07-15T08:35:10.546Z",
"workspace": {
"id": "$PRISMA_WORKSPACE_ID",
"name": "$PRISMA_WORKSPACE_NAME"
}
}
}

从输出中复制并存储 $PRISMA_PROJECT_ID。这是你的 Prisma 项目 ID,你将在下一步中使用它。

¥Copy and store the $PRISMA_PROJECT_ID from the output. This is your Prisma project ID, which you will use in the next step.

6. 在 GitHub 中添加密钥信息

¥ Add secrets in GitHub

添加密钥:

¥To add secrets:

  1. 转到你的 GitHub 代码库。

    ¥Go to your GitHub repository.

  2. 导航至“设置”。

    ¥Navigate to Settings.

  3. 点击并展开“密钥和变量”部分。

    ¥Click and expand the Secrets and variables section.

  4. 点击“操作”。

    ¥Click Actions.

  5. 点击“新建存储库密钥”。

    ¥Click New repository secret.

  6. 添加以下内容:

    ¥Add the following:

    • PRISMA_PROJECT_ID - 来自 Prisma 控制台的 Prisma 项目 ID。

      ¥PRISMA_PROJECT_ID - Your Prisma project ID from the Prisma Console.

    • PRISMA_POSTGRES_SERVICE_TOKEN - 你的服务令牌。

      ¥PRISMA_POSTGRES_SERVICE_TOKEN - Your service token.

这些密钥将通过 env 在工作流文件中访问。

¥These secrets will be accessed in the workflow file via env.

7. 尝试工作流程

¥ Try the workflow

你可以通过两种方式测试设置:

¥You can test the setup in two ways:

选项 1:通过 PR 自动触发

¥Option 1: Automatic trigger via PR

  1. 在代码库上打开拉取请求。

    ¥Open a pull request on the repository.

  2. GitHub Actions 将配置一个新的 Prisma Postgres 数据库。

    ¥GitHub Actions will provision a new Prisma Postgres database.

  3. 它将推送你的模式并播种数据库。

    ¥It will push your schema and seed the database.

  4. 将在 PR 中添加一条评论,确认数据库已创建。

    ¥A comment will be added to the PR confirming database creation.

  5. 拉取请求关闭后,数据库将被自动删除。

    ¥When the PR is closed, the database will be deleted automatically.

选项 2:手动触发

¥Option 2: Manual trigger

  1. 转到你代码库的“Actions”选项卡。

    ¥Go to the Actions tab in your repository.

  2. 在左侧边栏中选择 Prisma Postgres 管理 API 工作流。

    ¥Select the Prisma Postgres Management API Workflow on the left sidebar.

  3. 点击“运行”工作流下拉菜单

    ¥Click the Run workflow dropdown

  4. 选择 provision 作为操作,并可选择提供自定义数据库名称。你还可以选择 cleanup 来删除现有数据库。

    ¥Choose provision as the action and optionally provide a custom database name. You can also choose cleanup to delete an existing database.

  5. 点击“运行工作流”。

    ¥Click Run workflow.

下一步

¥Next steps

现在,你拥有一个完全自动化的 GitHub Actions 设置,用于管理 Prisma Postgres 临时数据库。

¥You now have a fully automated GitHub Actions setup for managing ephemeral Prisma Postgres databases.

这将为你提供:

¥This gives you:

  • 每个拉取请求都对应独立的数据库。

    ¥Isolated databases for every pull request.

  • 自动模式同步和播种。

    ¥Automatic schema sync and seed.

  • 合并后清理未使用的数据库。

    ¥Cleanup of unused databases after merges.

此设置提高了对更改的信心,并降低了共享数据库冲突的风险。你可以通过集成测试套件或将其集成到你的工作流程中来扩展此功能。

¥This setup improves confidence in changes and reduces the risk of shared database conflicts. You can extend this by integrating test suites, or integrating it in your workflow.


Stay connected with Prisma

Continue your Prisma journey by connecting with our active community. Stay informed, get involved, and collaborate with other developers:

We genuinely value your involvement and look forward to having you as part of our community!