> ## Documentation Index
> Fetch the complete documentation index at: https://www.unkey.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Unkey is two separate products. Compute builds, deploys, and runs apps behind a gateway. API Management issues API keys, enforces rate limits, manages identities and permissions, and reports usage. Say which product a page belongs to; a reader can use either without the other.
> Every Unkey API endpoint is an HTTP POST to https://api.unkey.com/v2/{service}.{procedure} with a root key in the Authorization: Bearer header. Root keys are workspace scoped.
> Error codes have the form err:{system}:{category}:{specific} and each has a page at /errors/{system}/{category}/{specific}.
> The word environment means production or preview in Compute. Rate limiting has four meanings on this site; the glossary lists them.

# PlanetScale

> Connect a PlanetScale database to your app and let Unkey create and rotate its credentials.

> [!NOTE]
>
> The PlanetScale integration is in preview. To enable it for your workspace, email [support@unkey.com](mailto:support@unkey.com).

Connect a PlanetScale database to your app (A Compute app: a deployable service inside a project. Not 'your application' in general.) and Unkey handles the credentials for you. You never copy a password into an environment variable: each deployment gets its own credential when it starts, and Unkey deletes it after the deployment stops. Unkey supports PlanetScale Postgres, Vitess (MySQL), and Neki.

## How it works

Below is an example of an app with a PlanetScale database named `orders`, which has a `main` branch and a `preview` branch:

```text theme={"system"}
┌─────────────────────────────────────┐
│ PlanetScale account                 │
└──────────────────┬──────────────────┘
                   │
┌──────────────────┴──────────────────┐
│ Database "orders"                   │
│ Branches: main, preview             │
└────────┬───────────────────┬────────┘
         │                   │
┌────────┴────────┐ ┌────────┴────────┐
│ production      │ │ preview         │
│ branch: main    │ │ branch: preview │
└────────┬────────┘ └────────┬────────┘
         │                   │
┌────────┴────────┐ ┌────────┴────────┐
│ deployment      │ │ deployment      │
│ own password    │ │ own password    │
└─────────────────┘ └─────────────────┘
```

1. Connect your PlanetScale account to your Unkey workspace once, with OAuth. See [Connect and disconnect](https://www.unkey.com/docs/compute/integrations/planetscale/connect.md).
2. Add the `orders` database to your project. It can be an existing database or one you create from the dashboard.
3. Connect each environment (A production or preview environment of a Compute app, not the dashboard label on a key.) of your app to one branch. Here, production reads and writes `main`, and preview reads and writes `preview`. You also pick the variable name your app reads the database URL from, such as `ORDERS_URL`. See [Production and preview](https://www.unkey.com/docs/compute/concepts/production-and-preview.md) for how environments and deployments relate.
4. Every new deployment gets its own username and password on its environment's branch. Unkey puts the connection URL in `ORDERS_URL`, plus `ORDERS_UNPOOLED_URL` on Postgres. Production and preview use the same names, but each points at its own branch. See [Environment variables](https://www.unkey.com/docs/compute/integrations/planetscale/environment-variables.md). [Deployments from fork pull requests](https://www.unkey.com/docs/compute/integrations/planetscale/credentials-and-security.md#pull-requests-from-forks) get no credentials.

## Limits

| Rule | Limit |
| - | - |
| Databases per project | 20 |
| Times you can add the same PlanetScale database to one project | Once. Every app in the project uses that one entry. |
| Branches one environment can use from one database | One. For example, production can use `main` while preview uses `preview`, but production can't use both. |
| Credentials | One per deployment per database, plus one when the read-only URL is on |

## Next steps

> [card] [Connect and disconnect](https://www.unkey.com/docs/compute/integrations/planetscale/connect.md)
>
> Connect your PlanetScale account and databases, and disconnect them later.

> [card] [Environment variables](https://www.unkey.com/docs/compute/integrations/planetscale/environment-variables.md)
>
> The URLs your app reads, and the read-only replica URL.

> [card] [Migrations](https://www.unkey.com/docs/compute/integrations/planetscale/migrations.md)
>
> Run schema changes with a PlanetScale credential.

> [card] [Credentials and security](https://www.unkey.com/docs/compute/integrations/planetscale/credentials-and-security.md)
>
> What each credential can do, when it is deleted, and how Unkey stores secrets.

> [card] [Troubleshooting](https://www.unkey.com/docs/compute/integrations/planetscale/troubleshooting.md)
>
> Fix a disconnected account and failed deployments.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.