Skip to content

Commit 59e05cb

Browse files
authored
Add TiDB serverless branching in Vercel integration (#14835)
1 parent 6a00b92 commit 59e05cb

File tree

6 files changed

+77
-26
lines changed

6 files changed

+77
-26
lines changed
Loading
Loading
100 KB
Loading
Loading
Loading

tidb-cloud/integrate-tidbcloud-with-vercel.md

Lines changed: 77 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This guide describes how to connect your TiDB Cloud clusters to Vercel projects
1818

1919
For both of the preceding methods, TiDB Cloud provides the following options for programmatically connecting to your database:
2020

21-
- Direct connection: connect your TiDB Cloud cluster to your Vercel project directly using MySQL's standard connection system.
21+
- Cluster: connect your TiDB Cloud cluster to your Vercel project with direct connections or [serverless driver](/tidb-cloud/serverless-driver.md).
2222
- [Data App](/tidb-cloud/data-service-manage-data-app.md): access data of your TiDB Cloud cluster through a collection of HTTP endpoints.
2323

2424
## Prerequisites
@@ -48,7 +48,7 @@ You are expected to have an account and a cluster in TiDB Cloud. If you do not h
4848

4949
> **Note:**
5050
>
51-
> For TiDB Dedicated clusters, make sure that the traffic filter of the cluster allows all IP addresses (set to `0.0.0.0/0`) for connection, because Vercel deployments use [dynamic IP addresses](https://vercel.com/guides/how-to-allowlist-deployment-ip-address). If you use the TiDB Cloud Vercel integration, TiDB Cloud automatically adds a `0.0.0.0/0` traffic filter to your cluster in the integration workflow if there is none.
51+
> For TiDB Dedicated clusters, make sure that the traffic filter of the cluster allows all IP addresses (set to `0.0.0.0/0`) for connection, because Vercel deployments use [dynamic IP addresses](https://vercel.com/guides/how-to-allowlist-deployment-ip-address).
5252
5353
To [integrate with Vercel via the TiDB Cloud Vercel Integration](#connect-via-the-tidb-cloud-vercel-integration), you are expected to be in the `Organization Owner` role of your organization or the `Project Owner` role of the target project in TiDB Cloud. For more information, see [User roles](/tidb-cloud/manage-user-access.md#user-roles).
5454

@@ -69,10 +69,16 @@ One Vercel project can only connect to one TiDB Cloud Data App. To change the Da
6969

7070
To connect via the TiDB Cloud Vercel integration, go to the [TiDB Cloud integration](https://vercel.com/integrations/tidb-cloud) page from the [Vercel's Integrations Marketplace](https://vercel.com/integrations). Using this method, you can choose which cluster to connect to, and TiDB Cloud will automatically generate all the necessary environment variables for your Vercel projects.
7171

72+
> **Note:**
73+
>
74+
> This method is only available for TiDB Serverless clusters. If you want to connect to a TiDB Dedicated cluster, use the [manual method](#connect-via-manually-setting-environment-variables).
75+
76+
### Integration workflow
77+
7278
The detailed steps are as follows:
7379

7480
<SimpleTab>
75-
<div label="Direct connection">
81+
<div label="Cluster">
7682

7783
1. Click **Add Integration** in the upper-right area of the [TiDB Cloud Vercel integration](https://vercel.com/integrations/tidb-cloud) page. The **Add TiDB Cloud** dialog is displayed.
7884
2. Select the scope of your integration in the drop-down list and click **Continue**.
@@ -84,8 +90,10 @@ The detailed steps are as follows:
8490
2. Select your target TiDB Cloud organization and project.
8591
3. Select **Cluster** as your connection type.
8692
4. Select your target TiDB Cloud cluster. If the **Cluster** drop-down list is empty or you want to select a new TiDB Serverless cluster, click **+ Create Cluster** in the list to create one.
87-
5. Select the framework that your Vercel projects are using. If the target framework is not listed, select **General**. Different frameworks determine different environment variables.
88-
6. Click **Add Integration and Return to Vercel**.
93+
5. Select the database that you want to connect to. If the **Database** drop-down list is empty or you want to select a new Database, click **+ Create Database** in the list to create one.
94+
6. Select the framework that your Vercel projects are using. If the target framework is not listed, select **General**. Different frameworks determine different environment variables.
95+
7. Choose whether to enable **Branching** to create new branches for preview environments.
96+
8. Click **Add Integration and Return to Vercel**.
8997

9098
![Vercel Integration Page](/media/tidb-cloud/vercel/integration-link-cluster-page.png)
9199

@@ -100,15 +108,16 @@ The detailed steps are as follows:
100108
TIDB_PORT
101109
TIDB_USER
102110
TIDB_PASSWORD
111+
TIDB_DATABASE
103112
```
104113

105-
For TiDB Dedicated clusters, the root CA is set in this variable:
114+
**Prisma**
106115

107116
```
108-
TIDB_SSL_CA
117+
DATABASE_URL
109118
```
110119

111-
**Prisma**
120+
**TiDB Cloud Serverless Driver**
112121

113122
```
114123
DATABASE_URL
@@ -145,19 +154,74 @@ The detailed steps are as follows:
145154
</div>
146155
</SimpleTab>
147156

157+
### Configure connections
158+
159+
If you have installed [TiDB Cloud Vercel integration](https://vercel.com/integrations/tidb-cloud), you can add or remove connections inside the integration.
160+
161+
1. In your Vercel dashboard, click **Integrations**.
162+
2. Click **Manage** in the TiDB Cloud entry.
163+
3. Click **Configure**.
164+
4. Click **Add Link** or **Remove** to add or remove connections.
165+
166+
![Vercel Integration Configuration Page](/media/tidb-cloud/vercel/integration-vercel-configuration-page.png)
167+
168+
When you remove a connection, the environment variables set by the integration workflow are removed from the Vercel project, too. However, this action does not affect the data of the TiDB Serverless cluster.
169+
170+
### Connect with TiDB Serverless branching
171+
172+
Vercel's [Preview Deployments](https://vercel.com/docs/deployments/preview-deployments) feature allows you to preview changes to your app in a live deployment without merging those changes to your Git project's production branch. With [TiDB Serverless Branching](/tidb-cloud/branch-overview.md), you can create a new instance for each branch of your Vercel project. This allows you to preview app changes in a live deployment without affecting your production data.
173+
174+
> **Note:**
175+
>
176+
> Currently, TiDB Serverless branching only supports [Vercel projects associated with GitHub repositories](https://vercel.com/docs/deployments/git/vercel-for-github).
177+
178+
To enable TiDB Serverless Branching, you need to ensure the following in the [TiDB Cloud Vercel integration workflow](#integration-workflow):
179+
180+
1. Select **Cluster** as your connection type.
181+
2. Enable **Branching** to create new branches for preview environments.
182+
183+
After you push changes to the Git repository, Vercel will trigger a preview deployment. TiDB Cloud integration will automatically create a TiDB Serverless branch for the Git branch and set environment variables. The detailed steps are as follows:
184+
185+
1. Create a new branch in your Git repository.
186+
187+
```shell
188+
cd tidb-prisma-vercel-demo1
189+
git checkout -b new-branch
190+
```
191+
192+
2. Add some changes and push the changes to the remote repository.
193+
3. Vercel will trigger a preview deployment for the new branch.
194+
195+
![Vercel Preview_Deployment](/media/tidb-cloud/vercel/vercel-preview-deployment.png)
196+
197+
1. During the deployment, TiDB Cloud integration will automatically create a TiDB Serverless branch with the same name as the Git branch. If the TiDB Serverless branch already exists, TiDB Cloud integration will skip this step.
198+
199+
![TiDB_Cloud_Branch_Check](/media/tidb-cloud/vercel/tidbcloud-branch-check.png)
200+
201+
2. After the TiDB Serverless branch is ready, TiDB Cloud integration will set environment variables in the preview deployment for the Vercel project.
202+
203+
![Preview_Envs](/media/tidb-cloud/vercel/preview-envs.png)
204+
205+
3. TiDB Cloud integration will also register a blocking check to wait for the TiDB Serverless branch to be ready. You can rerun the check manually.
206+
4. After the check is passed, you can visit the preview deployment to see the changes.
207+
208+
> **Note:**
209+
>
210+
> Due to a limitation of Vercel deployment workflow, the environment variable cannot be ensured to be set in the deployment. In this case, you need to redeploy the deployment.
211+
212+
> **Note:**
213+
>
214+
> For each organization in TiDB Cloud, you can create a maximum of five TiDB Serverless branches by default. To avoid exceeding the limit, you can delete the TiDB Serverless branches that are no longer needed. For more information, see [Manage TiDB Serverless branches](/tidb-cloud/branch-manage.md).
215+
148216
## Connect via manually setting environment variables
149217

150218
<SimpleTab>
151-
<div label="Direct connection">
219+
<div label="Cluster">
152220

153221
1. Get the connection information of your TiDB cluster.
154222

155223
You can get the connection information from the connection dialog of your cluster. To open the dialog, go to the [**Clusters**](https://tidbcloud.com/console/clusters) page of your project, click the name of your target cluster to go to its overview page, and then click **Connect** in the upper-right corner.
156224

157-
> **Note:**
158-
>
159-
> For TiDB Dedicated clusters, make sure that you have set the **Allow Access from Anywhere** traffic filter in this step.
160-
161225
2. Go to your Vercel dashboard > Vercel project > **Settings** > **Environment Variables**, and then [declare each environment variable value](https://vercel.com/docs/concepts/projects/environment-variables#declare-an-environment-variable) according to the connection information of your TiDB cluster.
162226

163227
![Vercel Environment Variables](/media/tidb-cloud/vercel/integration-vercel-environment-variables.png)
@@ -200,16 +264,3 @@ You can get the information of `<User>`, `<Password>`, `<Endpoint>`, `<Port>`, a
200264

201265
</div>
202266
</SimpleTab>
203-
204-
## Configure connections
205-
206-
If you have installed [TiDB Cloud Vercel integration](https://vercel.com/integrations/tidb-cloud), you can add or remove connections inside the integration.
207-
208-
1. In your Vercel dashboard, click **Integrations**.
209-
2. Click **Manage** in the TiDB Cloud entry.
210-
3. Click **Configure**.
211-
4. Click **Add Link** or **Remove** to add or remove connections.
212-
213-
![Vercel Integration Configuration Page](/media/tidb-cloud/vercel/integration-vercel-configuration-page.png)
214-
215-
When you remove a connection, environment variables set by the integration workflow are removed from the Vercel project either. The traffic filter and the data of the TiDB Cloud cluster are not affected.

0 commit comments

Comments
 (0)