PlanetScale
Connect
Connect PlanetScale from the terminal. Pass --help for the flags PlanetScale accepts, plus --no-browser for headless environments.
polylane cloud connect --provider planetscaleOAuth authorization, or a service token from your PlanetScale organization settings.
Connect one PlanetScale organization with OAuth or with a service token. Polylane encrypts the credential before it stores it, and the agent never sees it.
- In Polylane, click Connect with PlanetScale.
- On PlanetScale, approve the access that Polylane asks for.
- If your PlanetScale account can open more than one organization, pick the organization to connect.
- PlanetScale sends you back to Polylane, and the first sync starts.
To connect without a browser, use a service token. The steps are under Service token.
Connect PlanetScale from a CI job or any other environment without a browser.
You can connect PlanetScale without a browser. A CI job can call the same endpoint that the console calls. One authenticated POST creates the connection and starts the first sync.
Prerequisites
- A Polylane API key with the
cloud_accounts:writeandcloud_accounts:readscopes. See API keys and OAuth. - Your workspace ID, which starts with
ws_. Read it fromGET /v1/workspaceswith the same key. - A PlanetScale service token ID and token from your organization's Settings → Service tokens, with
read_organizationandread_databases. The OAuth flow needs a browser. A service token does not.
Create the connection
curl -X POST https://api.polylane.com/v1/cloud_accounts \
-H "x-api-key: $POLYLANE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"provider": "planetscale",
"workspaceId": "ws_0abc123",
"tokenId": "<service-token-id>",
"token": "<service-token>",
"organization": "my-org"
}'
One call connects one PlanetScale organization.
- You can leave out
organizationonly when the token opens exactly one organization. Otherwise the call fails with a400that lists the organization names that the token can open.
The response lists the connected accounts, and the first sync is already running. This example shows only the two fields that the next steps read:
{
"success": true,
"result": {
"provider": "planetscale",
"accounts": [{ "id": "acc_34gky74ibc92h8t2efn8csrh", "status": "syncing" }],
"failures": []
}
}
An account that is already connected goes into failures, not accounts. A repeated call never makes a second connection.
Wait for the first sync
Poll each returned account by its id until status is ready. The status is new at registration and syncing while resources arrive:
until [ "$(curl -s "https://api.polylane.com/v1/cloud_accounts/$WORKSPACE_ID/$ACCOUNT_ID" \
-H "x-api-key: $POLYLANE_API_KEY" | jq -r '.result.status')" = "ready" ]; do
sleep 15
done
Give the loop a deadline, so that a failed connection fails the job and does not stop it indefinitely. When the account is ready, its resources are in the topology and Polylane has started its first check.
Disconnect from the API
Deleting the connection stops every sync and check and deletes the credentials that Polylane held. The call needs the cloud_accounts:delete scope:
curl -X DELETE "https://api.polylane.com/v1/cloud_accounts/$WORKSPACE_ID/$ACCOUNT_ID" \
-H "x-api-key: $POLYLANE_API_KEY"
Then delete the service token in PlanetScale, as the Disconnecting section tells.
How it works
Access
The OAuth grant gives Polylane read access to the organization, its members, databases, branches, backups, deploy requests and comments. The grant also includes permission to restore backups. A service token gets only the permissions that you give it.
Infrastructure graph
Polylane syncs the organization every 15 minutes. Each database and each branch becomes a node, with its state, kind, region, production flag, parent branch and schema activity. A database contains its branches. Polylane reads the connection hosts of each branch, so a service that connects to a branch, for example through a Cloudflare Hyperdrive configuration, links to that branch on the topology.
Query Insights and checks
Polylane reads Query Insights for each database and branch. The charts show queries, query errors, p99 latency, rows read, rows returned and query time. PlanetScale has no logs API, so Polylane reads failing queries from Query Insights as the error lines of the branch.
Polylane monitors production branches only. By default, it runs these checks every 30 minutes:
- Latency anomalies that PlanetScale itself detects. One anomaly opens an issue.
- Query errors, compared with the history of the account.
- Worst p99 latency of a query pattern, compared with the history of the account.
- Query volume. A drop to zero queries on a busy branch can mean that an application lost its connection.
- Credentials. A revoked grant or a deleted token stops the sync, so Polylane checks the credential on each run.
Investigations
During an investigation, agents read Query Insights for one branch: top query patterns, error groups and latency anomaly windows. Agents can also read other PlanetScale API endpoints, such as backups and deploy requests.
Writes
The PlanetScale API tool can create branches, promote branches and restore backups. Connections start in read-only mode, so Polylane refuses each write until a workspace admin turns read-only mode off. After that, each write needs safety review and your approval before it runs.
Service token
Use a service token for a long-lived credential, or to connect from a script.
- In PlanetScale, open your organization's Settings → Service tokens.
- Click Create service token. Copy the token ID and the token.
- Grant the token
read_organizationandread_databases. - Paste the token ID and the token into Polylane. If the token can open more than one organization, also enter the name of the organization to connect.
- Polylane checks the token and starts the first sync.
Troubleshooting
"PlanetScale does not recognize this service token" error
- You must give the token ID and the token. The token alone cannot authenticate.
- Make sure that the token is not deleted in PlanetScale.
"This PlanetScale service token cannot read your organization" error
- In PlanetScale, open Settings → Service tokens, select the token, and grant
read_organizationandread_databases.
"Multiple PlanetScale organizations are reachable" error
- The credential can open more than one organization. Name the organization to connect.
- With OAuth in the console, pick the organization when Polylane asks.
- With the API, set the
organizationfield to the organization name.
"PlanetScale no longer accepts this authorization" error
- PlanetScale revoked the OAuth grant. Connect PlanetScale again to authorize Polylane.
Missing resources
- The first sync can take a few minutes.
- Click Sync in the account header to start a sync immediately.
Disconnecting
Disconnecting stops every sync and check, and deletes the credential that Polylane stored. The OAuth grant stays in PlanetScale until you revoke it there. If you connected with a service token, delete the token in your PlanetScale organization settings.
Disconnect
Disconnecting stops every sync and check and deletes the credentials Polylane held. Polylane removes what PlanetScale's API lets it remove. The following stays until you remove it yourself:
- OAuth grant
polylane cloud disconnect <id>Tools
2Operations agents can perform in threads.
Supported resources
2Resource types that show up in your infrastructure graph.