Edits history of script submission #11016 for ' Start an Online Migration (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Start an Online Migration
     * 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.
     */
    export async function main(
      auth: Digitalocean,
      database_cluster_uuid: string,
      body: {
        source?: {
          host?: string;
          port?: number;
          dbname?: string;
          username?: string;
          password?: string;
        };
        disable_ssl?: false | true;
        ignore_dbs?: string[];
      },
    ) {
      const url = new URL(
        `https://api.digitalocean.com/v2/databases/${database_cluster_uuid}/online-migration`,
      );
    
      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 537 days ago