home / skills / openclaw / skills / pscale-branch

This skill helps you manage PlanetScale branches, enabling creation, promotion, diff checks, and lifecycle workflows for safe schema migrations.

npx playbooks add skill openclaw/skills --skill pscale-branch

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
5.4 KB
---
name: pscale-branch
description: Create, delete, promote, diff, and manage PlanetScale database branches. Use when creating development branches for schema changes, viewing schema diffs, promoting branches to production, or managing branch lifecycle. Essential for schema migration workflows. Triggers on branch, create branch, schema diff, promote branch, development branch, database branch.
---

# pscale branch

Create, delete, diff, and manage database branches.

## Common Commands

```bash
# Create branch from main
pscale branch create <database> <branch-name>

# Create branch from specific source
pscale branch create <database> <branch-name> --from <source-branch>

# List all branches
pscale branch list <database>

# Show branch details
pscale branch show <database> <branch-name>

# View schema diff
pscale branch diff <database> <branch-name>

# View schema
pscale branch schema <database> <branch-name>

# Delete branch
pscale branch delete <database> <branch-name>

# Promote to production
pscale branch promote <database> <branch-name>
```

## Workflows

### Schema Migration Workflow (Standard)

```bash
# 1. Create development branch
pscale branch create my-database feature-migration --from main

# 2. Make schema changes (via shell, ORM, or direct SQL)
pscale shell my-database feature-migration
# ... run ALTER TABLE, CREATE TABLE, etc.

# 3. View changes
pscale branch diff my-database feature-migration

# 4. Create deploy request (safer than direct promotion)
pscale deploy-request create my-database feature-migration

# 5. Deploy via deploy request (see pscale-deploy-request)
```

### Quick Branch for MR/PR

```bash
# Match PlanetScale branch to your MR/PR branch
BRANCH_NAME="feature-add-user-preferences"
pscale branch create my-database $BRANCH_NAME --from main
```

See `scripts/create-branch-for-mr.sh` for automation.

### Schema Comparison

```bash
# Compare branch schema with main
pscale branch diff <database> <branch-name>

# View full branch schema
pscale branch schema <database> <branch-name>

# Export schema to file
pscale branch schema <database> <branch-name> > schema.sql
```

### Branch Cleanup

```bash
# List all branches
pscale branch list <database>

# Delete merged/stale branches
pscale branch delete <database> <old-branch-name>
```

## Decision Trees

### Should I promote directly or use deploy request?

```
What's your environment?
├─ Production database → ALWAYS use deploy request (safe, reviewable)
├─ Pre-production database with team → Use deploy request (review workflow)
├─ Personal dev database → Direct promotion OK (but deploy request still safer)
└─ Experimental changes → Keep as branch, don't promote
```

### When to create a new branch?

```
What's your goal?
├─ Schema migration for feature → Create branch (from main)
├─ Testing schema changes → Create branch (isolated)
├─ Hotfix schema change → Create branch (from production)
├─ Experiment / spike → Create branch (delete after)
└─ Working on existing schema → Use existing branch
```

## Troubleshooting

### "Branch already exists"

**Solution:**
```bash
# Check existing branches
pscale branch list <database>

# Use different name or delete existing
pscale branch delete <database> <existing-branch>
```

### Schema diff shows no changes

**Causes:**
- No schema changes made yet
- Changes not committed in database session
- Comparing branch to itself

**Solution:**
```bash
# Verify schema was modified
pscale branch schema <database> <branch-name>

# Ensure you're in the right branch when making changes
pscale shell <database> <branch-name>
```

### Cannot delete branch

**Error:** "Branch is protected" or "Branch is a production branch"

**Solution:**
```bash
# Demote production branch first
pscale branch demote <database> <branch-name>

# Then delete
pscale branch delete <database> <branch-name>
```

### Branch creation fails

**Common causes:**
- Invalid branch name (spaces, special chars)
- Source branch doesn't exist
- Insufficient permissions

**Solution:**
```bash
# Use valid branch name (alphanumeric, hyphens, underscores)
pscale branch create <database> my-feature-branch --from main

# Verify source branch exists
pscale branch list <database> | grep main
```

## Related Skills

- **pscale-deploy-request** - Create deploy requests from branches (safer than direct promotion)
- **pscale-database** - Database management
- **drizzle-kit** - ORM-based schema migrations (generates SQL for pscale shell)
- **gitlab-cli-skills** - MR/PR integration (match branch names across tools)

## References

See `references/commands.md` for complete `pscale branch` command reference.

## Branch Lifecycle

```
main (production)
  │
  ├─ Create branch ──> feature-branch (development)
  │                         │
  │                         ├─ Make schema changes
  │                         ├─ Test changes
  │                         └─ Create deploy request
  │                               │
  └─ Deploy ←──────────────────────┘
```

## Best Practices

1. **Always create branches from main** for schema changes
2. **Use descriptive branch names** matching MR/PR numbers when applicable
3. **Run diff before deploy request** to review changes
4. **Delete merged branches** to keep branch list clean
5. **Use deploy requests** instead of direct promotion (reviewable, revertable)
6. **Test schema changes** in branch before deploying

Overview

This skill manages PlanetScale database branches: create, list, show, diff, promote, and delete. It supports development workflows for schema changes, lets you inspect schema diffs, and helps promote or clean up branches in a controlled way. Use it to integrate branch-based schema migrations into CI/CD and pull request workflows.

How this skill works

The skill wraps common pscale branch operations to create branches from main or another source, list and show branch details, export or view full branch schemas, and display schema diffs. It supports creating deploy requests and promoting branches to production while also handling branch lifecycle tasks like deletion and demotion. Commands run against a specified database and branch name, returning clear outputs for review and automation.

When to use it

  • Creating an isolated development branch for a schema migration or feature
  • Viewing schema diffs before submitting a deploy request or PR
  • Promoting a tested branch to production or a pre-production environment
  • Cleaning up merged or stale branches to keep the branch list tidy

Best practices

  • Create branches from main for schema changes to maintain a clear migration path
  • Use descriptive branch names that match MR/PR identifiers for traceability
  • Run pscale branch diff and review SQL changes before creating a deploy request
  • Prefer deploy requests over direct promotion for production databases
  • Delete merged or unused branches to reduce clutter and accidental promotions

Example use cases

  • Create a feature branch for a migration: pscale branch create my-db feature-x --from main
  • Compare branch vs main before deploy: pscale branch diff my-db feature-x
  • Promote a validated branch via deploy request workflow to production
  • Spin up a temporary branch per pull request for CI tests and then delete it
  • Export branch schema to a file for offline review or backup: pscale branch schema my-db feature-x > schema.sql

FAQ

Should I ever promote directly to production?

Direct promotion is acceptable for personal dev databases, but always use a deploy request for production to enable reviews and safer rollbacks.

What if pscale branch diff shows no changes?

Verify you made schema changes in the correct branch session and that changes were applied; use pscale branch schema to inspect the full schema.