Edits history of script submission #10747 for ' Create a Read-only Replica (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Create a Read-only Replica
     * To create a read-only replica for a PostgreSQL or MySQL database cluster, send a POST request to `/v2/databases/$DATABASE_ID/replicas` specifying the name it should be given, the size of the node to be used, and the region where it will be located.
     */
    export async function main(
      auth: Digitalocean,
      database_cluster_uuid: string,
      body: {
        id?: string;
        name: string;
        region?: string;
        size?: string;
        status?: "creating" | "online" | "resizing" | "migrating" | "forking";
        tags?: string[];
        created_at?: string;
        private_network_uuid?: string;
        connection?: {} & {
          uri?: string;
          database?: string;
          host?: string;
          port?: number;
          user?: string;
          password?: string;
          ssl?: false | true;
        };
        private_connection?: {} & {
          uri?: string;
          database?: string;
          host?: string;
          port?: number;
          user?: string;
          password?: string;
          ssl?: false | true;
        };
        storage_size_mib?: number;
      },
    ) {
      const url = new URL(
        `https://api.digitalocean.com/v2/databases/${database_cluster_uuid}/replicas`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        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