GitHub 集成
Connect with GitHub to sync branches with your repository
Supabase 分支使用 Supabase 的 GitHub 集成来读取你 GitHub 仓库中的文件。通过这个集成,Supabase 会监控你 GitHub 仓库的所有提交、分支和拉取请求。
🌐 Supabase Branching uses the Supabase GitHub integration to read files from your GitHub repository. With this integration, Supabase watches all commits, branches, and pull requests of your GitHub repository.
安装 #
🌐 Installation
在 Supabase 控制台中:
🌐 In the Supabase Dashboard:
- 前往 项目设置 > 集成。
- 在 GitHub 集成 下,点击 授权 GitHub。
- 你会被重定向到 GitHub 授权页面。点击 授权 Supabase。
- 你会被重定向回集成页面。选择一个 GitHub 仓库来连接你的项目。
- 设置 工作目录 字段。
- 根据需要配置其他选项,以自动化你的 GitHub 连接。
- 点击 启用集成。
设置工作目录 #
🌐 Set the working directory
工作目录是从你的仓库根目录到包含 supabase/ 文件夹的目录的路径。当 supabase/ 位于仓库根目录时,输入 .。
🌐 The working directory is the path from your repository root to the directory that contains the supabase/ folder. Enter . when supabase/ is at the repository root.
如果 supabase/ 在你的仓库里更深层次的目录中,输入它的上级目录就行。比如说,如果你的布局是 apps/web/supabase/,就输入 apps/web。
🌐 If supabase/ is nested deeper in your repository, enter its parent directory instead. For example, if your layout is apps/web/supabase/, enter apps/web.
准备你的 Git 仓库 #
🌐 Preparing your Git repository
你将使用 Supabase CLI 来初始化你本地的 ./supabase 目录:
🌐 You will be using the Supabase CLI to initialize your local ./supabase directory:
如果你没有 ./supabase 目录,你可以创建一个:
1supabase init使用 supabase db pull 拉取你的数据库更改。要获取你的数据库连接字符串,进入你的项目仪表板,点击 Connect,然后找到会话池连接字符串。
1supabase db pull --db-url <db_connection_string>23# Your Database connection string will look like this:4# postgres://postgres.xxxx:password@xxxx.pooler.supabase.com:5432/postgres如果你处在IPv6 环境下,或者拥有 IPv4 附加功能,你可以在会话模式下使用直接连接字符串,而不是 Supavisor。
把 supabase 目录提交到 Git,然后把你的更改推送到远程仓库。
1git add supabase2git commit -m "Initial migration"3git push同步 GitHub 分支 #
🌐 Syncing GitHub branches
在你的 GitHub 集成配置中启用 自动分支 选项,以便自动将 GitHub 分支与 Supabase 分支同步。
🌐 Enable the Automatic branching option in your GitHub Integration configuration to automatically sync GitHub branches with Supabase branches.
当在 GitHub 创建新分支时,Supabase 会创建对应的分支。(你可以启用 仅限 Supabase 更改 选项,这样只有在 Supabase 文件更改时才会创建 Supabase 分支。)
🌐 When a new branch is created in GitHub, a corresponding branch is created in Supabase. (You can enable the Supabase changes only option to only create Supabase branches when Supabase files change.)
配置 #
🌐 Configuration
你可以通过在 Supabase 目录中配置 config.toml 文件,在你的预览分支上测试配置更改。更多信息请参见 配置文档。
🌐 You can test configuration changes on your Preview Branch by configuring the config.toml file in your Supabase directory. See the Configuration docs for more information.
你的 PR 上会添加一条评论,显示你的预览分支的部署状态。
🌐 A comment is added to your PR with the deployment status of your preview branch.
迁移 #
🌐 Migrations
你 Supabase 目录下 migrations 子目录里的迁移会自动运行。
🌐 The migrations in the migrations subdirectory of your Supabase directory are automatically run.
播种 #
🌐 Seeding
不会有生产数据被复制到你的预览分支。这是为了保护你敏感的生产数据。
🌐 No production data is copied to your Preview branch. This is meant to protect your sensitive production data.
你可以使用 Supabase 目录中的 seed.sql 文件为你的预览分支填充示例数据。更多信息请查看 Seeding 文档。
🌐 You can seed your Preview Branch with sample data using the seed.sql file in your Supabase directory. See the Seeding docs for more information.
你种子文件中的数据更改不会合并到生产环境。
🌐 Data changes in your seed files are not merged to production.
将更改部署到生产环境 #
🌐 Deploying changes to production
在你的 GitHub 集成配置中启用 部署到生产环境 选项,这样当你推送或合并到生产分支时,变更会自动部署。
🌐 Enable the Deploy to production option in your GitHub Integration configuration to automatically deploy changes when you push or merge to production branch.
以下更改已部署:
🌐 The following changes are deployed:
- 新的迁移已应用
- 在
config.toml中声明的边缘函数已部署 config.toml中声明的存储桶已部署
所有其他配置,包括 API、认证和种子文件,默认都会被忽略。
🌐 All other configurations, including API, Auth, and seed files, are ignored by default.
防止迁移失败 #
🌐 Preventing migration failures
我们强烈建议为 Supabase 集成开启“必需检查”。你可以在 GitHub 仓库的设置中进行操作。这可以防止在迁移检查失败时合并 PR,并阻止无效的迁移被合并到你的生产分支。
🌐 We highly recommend turning on a 'required check' for the Supabase integration. You can do this from your GitHub repository settings. This prevents PRs from being merged when migration checks fail, and stops invalid migrations from being merged into your production branch.

电子邮件通知 #
🌐 Email notifications
为了尽早发现问题,我们还建议你订阅分支的邮件通知。常见错误包括迁移冲突、函数部署失败或配置文件无效。
🌐 To catch failures early, we also recommend subscribing to email notifications on your branch. Common errors include migration conflict, function deployment failure, or invalid configuration file.
你可以设置一个自定义的 GitHub Action 来监控任何 Supabase 分支的状态。
🌐 You can setup a custom GitHub Action to monitor the status of any Supabase Branch.
1name: Branch Status23on:4 pull_request:5 types:6 - opened7 - reopened8 - synchronize9 branches:10 - main11 - develop12 paths:13 - 'supabase/**'1415jobs:16 failed:17 runs-on: ubuntu-latest18 steps:19 - uses: fountainhead/action-wait-for-check@v1.2.020 id: check21 with:22 checkName: Supabase Preview23 ref: ${{ github.event.pull_request.head.sha || github.sha }}24 token: ${{ secrets.GITHUB_TOKEN }}2526 - if: ${{ steps.check.outputs.conclusion == 'failure' }}27 run: exit 1