0

Start an Online Migration

by
Published Dec 20, 2024

To start an online migration, send a PUT request to `/v2/databases/$DATABASE_ID/online-migration` endpoint. Migrating a cluster establishes a connection with an existing cluster and replicates its contents to the target cluster. Online migration is only available for MySQL, PostgreSQL, and Redis clusters.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Start an Online Migration
7
 * To start an online migration, send a PUT request to `/v2/databases/$DATABASE_ID/online-migration` endpoint. Migrating a cluster establishes a connection with an existing cluster and replicates its contents to the target cluster. Online migration is only available for MySQL, PostgreSQL, and Redis clusters.
8
 */
9
export async function main(
10
  auth: Digitalocean,
11
  database_cluster_uuid: string,
12
  body: {
13
    source?: {
14
      host?: string;
15
      port?: number;
16
      dbname?: string;
17
      username?: string;
18
      password?: string;
19
    };
20
    disable_ssl?: false | true;
21
    ignore_dbs?: string[];
22
  },
23
) {
24
  const url = new URL(
25
    `https://api.digitalocean.com/v2/databases/${database_cluster_uuid}/online-migration`,
26
  );
27

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