0

Configure a Database Cluster's Maintenance Window

by
Published Dec 20, 2024

To configure the window when automatic maintenance should be performed for a database cluster, send a PUT request to `/v2/databases/$DATABASE_ID/maintenance`. A successful request will receive a 204 No Content status code with no body in response.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Configure a Database Cluster's Maintenance Window
7
 * To configure the window when automatic maintenance should be performed for a database cluster, send a PUT request to `/v2/databases/$DATABASE_ID/maintenance`.
8
A successful request will receive a 204 No Content status code with no body in response.
9
 */
10
export async function main(
11
  auth: Digitalocean,
12
  database_cluster_uuid: string,
13
  body: {
14
    day: string;
15
    hour: string;
16
    pending?: false | true;
17
    description?: string[];
18
  },
19
) {
20
  const url = new URL(
21
    `https://api.digitalocean.com/v2/databases/${database_cluster_uuid}/maintenance`,
22
  );
23

24
  const response = await fetch(url, {
25
    method: "PUT",
26
    headers: {
27
      "Content-Type": "application/json",
28
      Authorization: "Bearer " + auth.token,
29
    },
30
    body: JSON.stringify(body),
31
  });
32
  if (!response.ok) {
33
    const text = await response.text();
34
    throw new Error(`${response.status} ${text}`);
35
  }
36
  return await response.json();
37
}
38