0

Update database settings

by
Published Oct 17, 2025

### Authorization A service token or OAuth token must have at least one of the following access or scopes in order to use this API endpoint: **Service Token Accesses** `write_database` **OAuth Scopes** | Resource | Scopes | | :------- | :---------- | | Organization | `write_databases` | | Database | `write_database` |

Script planetscale Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Planetscale = {
3
  serviceTokenId: string;
4
  serviceToken: string;
5
};
6
/**
7
 * Update database settings
8
 * 
9
### Authorization
10
A service token or OAuth token must have at least one of the following access or scopes in order to use this API endpoint:
11

12
**Service Token Accesses**
13
 `write_database`
14

15
**OAuth Scopes**
16

17
 | Resource | Scopes |
18
| :------- | :---------- |
19
| Organization | `write_databases` |
20
| Database | `write_database` |
21
 */
22
export async function main(
23
  auth: Planetscale,
24
  organization: string,
25
  name: string,
26
  body: {
27
    automatic_migrations?: false | true;
28
    migration_framework?: string;
29
    migration_table_name?: string;
30
    require_approval_for_deploy?: false | true;
31
    restrict_branch_region?: false | true;
32
    allow_data_branching?: false | true;
33
    insights_raw_queries?: false | true;
34
    production_branch_web_console?: false | true;
35
    default_branch?: string;
36
  },
37
) {
38
  const url = new URL(
39
    `https://api.planetscale.com/v1/organizations/${organization}/databases/${name}`,
40
  );
41

42
  const response = await fetch(url, {
43
    method: "PATCH",
44
    headers: {
45
      "Content-Type": "application/json",
46
      Authorization: `${auth.serviceTokenId}:${auth.serviceToken}`,
47
    },
48
    body: JSON.stringify(body),
49
  });
50
  if (!response.ok) {
51
    const text = await response.text();
52
    throw new Error(`${response.status} ${text}`);
53
  }
54
  return await response.json();
55
}
56