0

Scale, edit or upgrade a cluster

by
Published Oct 17, 2025

In addition to adding nodes and changing cluster fields, the PATCH Cluster endpoint can be used to upgrade the cluster version.

Script cockroachdb Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Cockroachdb = {
3
  token: string;
4
};
5
/**
6
 * Scale, edit or upgrade a cluster
7
 * In addition to adding nodes and changing cluster fields, the PATCH Cluster endpoint can be used to upgrade the cluster version.
8
 */
9
export async function main(
10
  auth: Cockroachdb,
11
  cluster_id: string,
12
  body: {
13
    cockroach_version?: string;
14
    dedicated?: {
15
      cmek_region_specs?: {
16
        key_spec?: {
17
          auth_principal?: string;
18
          type?: "AWS_KMS" | "GCP_CLOUD_KMS" | "NULL_KMS";
19
          uri?: string;
20
        };
21
        region?: string;
22
      }[];
23
      hardware?: {
24
        disk_iops?: number;
25
        machine_spec?: { machine_type?: string; num_virtual_cpus?: number };
26
        storage_gib?: number;
27
      };
28
      region_nodes?: {};
29
    };
30
    delete_protection?: "ENABLED" | "DISABLED";
31
    labels?: {};
32
    parent_id?: string;
33
    plan?: "BASIC" | "STANDARD" | "ADVANCED";
34
    serverless?: {
35
      primary_region?: string;
36
      regions?: string[];
37
      upgrade_type?: "MANUAL" | "AUTOMATIC";
38
      usage_limits?: {
39
        provisioned_virtual_cpus?: string;
40
        request_unit_limit?: string;
41
        storage_mib_limit?: string;
42
      };
43
    };
44
    upgrade_status?:
45
      | "FINALIZED"
46
      | "MAJOR_UPGRADE_RUNNING"
47
      | "UPGRADE_AVAILABLE"
48
      | "PENDING_FINALIZATION"
49
      | "ROLLBACK_RUNNING";
50
  },
51
) {
52
  const url = new URL(
53
    `https://cockroachlabs.cloud/api/v1/clusters/${cluster_id}`,
54
  );
55

56
  const response = await fetch(url, {
57
    method: "PATCH",
58
    headers: {
59
      "Content-Type": "application/json",
60
      Authorization: "Bearer " + auth.token,
61
    },
62
    body: JSON.stringify(body),
63
  });
64
  if (!response.ok) {
65
    const text = await response.text();
66
    throw new Error(`${response.status} ${text}`);
67
  }
68
  return await response.json();
69
}
70