//native
type Digitalocean = {
token: string;
};
/**
* Migrate a Database Cluster to a New Region
* To migrate a database cluster to a new region, send a `PUT` request to
`/v2/databases/$DATABASE_ID/migrate`. The body of the request must specify a
`region` attribute.
A successful request will receive a 202 Accepted status code with no body in
response. Querying the database cluster will show that its `status` attribute
will now be set to `migrating`. This will transition back to `online` when the
migration has completed.
*/
export async function main(
auth: Digitalocean,
database_cluster_uuid: string,
body: { region: string },
) {
const url = new URL(
`https://api.digitalocean.com/v2/databases/${database_cluster_uuid}/migrate`,
);
const response = await fetch(url, {
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 536 days ago