Skip to main content
This workflow creates a dedicated Xata branch for each pull request, allowing you to test database changes in isolation. It also manages PR comments to provide branch information and status updates.

Workflow Configuration

Authentication and Environment Variables

The workflow requires several environment variables to be set:
  • XATA_API_KEY: Your Xata API key (set as a GitHub secret)
  • XATA_ORGANIZATION_ID: Your Xata organization ID
  • XATA_PROJECT_ID: Your Xata project ID
  • XATA_BRANCH_ID: The ID of the main branch
  • XATA_BRANCH_NAME: The name of the main branch
  • XATA_DATABASE_NAME: Your database name
If you have the Xata CLI configured with your project locally, you can obtain these values with the following commands:

Required Permissions

The workflow requires the following GitHub permissions:

Workflow Steps

1. Find Previous Comment

This step searches for any existing comments from the workflow to update them later.

2. Checkout Code

This step checks out your repository code with full history and proper credentials configuration.

3. Install Dependencies

These steps install the required dependencies:
  • pnpm package manager
  • Xata CLI

4. Check Status and Migration State

These steps verify the current state of your Xata environment and check for any pending migrations.

5. Create or Update Comment

6. Branch Management

7. Migration Handling

8. Environment Setup

9. Final Comment Update

Concurrency Control

The workflow uses GitHub Actions concurrency to prevent multiple runs from interfering with each other:
This ensures that:
  • Only one workflow run per PR is active at a time
  • New runs cancel any in-progress runs
  • Prevents race conditions during branch creation

When to Use

Use this workflow when you want to:
  • Create isolated database environments for PRs
  • Test database changes in isolation
  • Provide preview environments for PR reviewers
  • Automate database branch management

Best Practices

  1. Set Appropriate Timeout
    • The workflow has a 10-minute timeout
    • Adjust based on your typical migration duration
  2. Use Environment Variables
    • Store sensitive information in GitHub secrets
    • Use environment variables for configuration
  3. Handle Migration States
    • Check for in-progress migrations
    • Complete pending migrations
    • Apply new migrations
  4. PR Communication
    • Keep PR comments updated
    • Provide clear connection instructions
    • Include relevant warnings