PlanetScale
PlanetScale is serverless MySQL with a Git-like branching workflow. Great for teams that need MySQL compatibility.
Table of Contents
- Overview
- Quick Start
- Environment Variables
- Branching Workflow
- Safe Migrations
- Foreign Key Considerations
- Connection String Format
- Regions
- Troubleshooting
- Insights
- Pricing
- Resources
Overview
| Feature | Value |
|---|---|
| Database | MySQL 8.0 |
| Protocol | HTTP |
| Free Tier | 5 GB storage, 1B row reads/mo |
| Best For | MySQL apps, branching workflow |
Quick Start
1. Create Account
Sign up at planetscale.com (GitHub login available).
2. Install CLI (Optional)
# macOS
brew install planetscale/tap/pscale
# Linux
curl -sSfL https://get.planetscale.com/download | bash
3. Create Database
Via Dashboard:
- Click New database
- Choose a region
- Name your database
Via CLI:
pscale auth login
pscale database create myapp --region us-east
4. Create Branch Password
- Go to Branches → main
- Click Connect
- Select Node.js → @planetscale/database
- Copy the connection string
5. Configure Juntos
Add to .env.local:
PLANETSCALE_URL=mysql://username:password@aws.connect.psdb.cloud/myapp?ssl={"rejectUnauthorized":true}
6. Deploy
bin/juntos db:prepare -d planetscale
bin/juntos deploy -d planetscale
Environment Variables
| Variable | Required | Description |
|---|---|---|
PLANETSCALE_URL |
Yes | Connection string from dashboard |
Branching Workflow
PlanetScale’s killer feature is database branching—like Git for your schema.
Create a Branch
# Via CLI
pscale branch create myapp add-users
# Or via dashboard
Make Schema Changes
Connect to your branch and run migrations:
# Point to development branch
PLANETSCALE_URL=mysql://...@add-users.aws.connect.psdb.cloud/myapp
bin/juntos db:migrate -d planetscale
Create Deploy Request
pscale deploy-request create myapp add-users
Review and Merge
- Review the schema diff in dashboard
- Approve the deploy request
- PlanetScale applies changes to main without downtime
Safe Migrations
PlanetScale uses Vitess for online schema changes. Large tables can be altered without locking:
# This won't lock the users table
add_column :users, :avatar_url, :string
Deploy Requests
For production changes, use deploy requests instead of direct migrations:
- Create branch:
pscale branch create myapp feature - Run migrations on branch
- Create deploy request
- Review schema diff
- Merge when ready
Foreign Key Considerations
PlanetScale doesn’t enforce foreign keys at the database level (Vitess limitation). Instead:
- Use application-level validations
- The schema still documents relationships
- Referential integrity is your responsibility
# Foreign keys are documented but not enforced
class Comment < ApplicationRecord
belongs_to :post
validates :post, presence: true # Application-level enforcement
end
Connection String Format
PlanetScale provides different connection formats. Use the @planetscale/database format for serverless:
mysql://username:password@aws.connect.psdb.cloud/database?ssl={"rejectUnauthorized":true}
Important: The SSL parameter is required for secure connections.
Regions
Choose a region close to your deployment:
| Region | Location |
|---|---|
us-east |
N. Virginia |
us-west |
Oregon |
eu-west |
Ireland |
ap-south |
Mumbai |
ap-southeast |
Singapore |
ap-northeast |
Tokyo |
Troubleshooting
Access denied
- Verify your password hasn’t expired
- Create a new password in the dashboard
- Update
.env.local
Foreign key errors
PlanetScale doesn’t support foreign key constraints. Remove foreign_key: true from migrations:
# Instead of:
add_reference :comments, :post, foreign_key: true
# Use:
add_reference :comments, :post
Connection timeout
PlanetScale connections may timeout after 5 minutes of inactivity. The adapter handles reconnection automatically.
Insights
PlanetScale provides query insights in the dashboard:
- Slow queries
- Query patterns
- Index recommendations
Use these to optimize your application.
Pricing
| Tier | Storage | Row Reads | Row Writes | Price |
|---|---|---|---|---|
| Hobby | 5 GB | 1B/mo | 10M/mo | $0 |
| Scaler | 10 GB | 100B/mo | 50M/mo | $29/mo |
The free tier is suitable for small to medium applications.