Edits history of script submission #18078 for ' Update database settings (planetscale)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Planetscale = {
      serviceTokenId: string;
      serviceToken: string;
    };
    /**
     * Update database settings
     * 
    ### Authorization
    A service token or OAuth token must have at least one of the following access or scopes in order to use this API endpoint:
    
    **Service Token Accesses**
     `write_database`
    
    **OAuth Scopes**
    
     | Resource | Scopes |
    | :------- | :---------- |
    | Organization | `write_databases` |
    | Database | `write_database` |
     */
    export async function main(
      auth: Planetscale,
      organization: string,
      name: string,
      body: {
        automatic_migrations?: false | true;
        migration_framework?: string;
        migration_table_name?: string;
        require_approval_for_deploy?: false | true;
        restrict_branch_region?: false | true;
        allow_data_branching?: false | true;
        insights_raw_queries?: false | true;
        production_branch_web_console?: false | true;
        default_branch?: string;
      },
    ) {
      const url = new URL(
        `https://api.planetscale.com/v1/organizations/${organization}/databases/${name}`,
      );
    
      const response = await fetch(url, {
        method: "PATCH",
        headers: {
          "Content-Type": "application/json",
          Authorization: `${auth.serviceTokenId}:${auth.serviceToken}`,
        },
        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 235 days ago