Edits history of script submission #20855 for ' Create a database branch (supabase)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Supabase = {
    	key: string
    }
    /**
     * Create a database branch
     * Creates a database branch from the specified project.
     */
    export async function main(
    	auth: Supabase,
    	ref: string,
    	body: {
    		branch_name: string
    		git_branch?: string
    		persistent?: false | true
    		region?: string
    		desired_instance_size?:
    			| 'pico'
    			| 'nano'
    			| 'micro'
    			| 'small'
    			| 'medium'
    			| 'large'
    			| 'xlarge'
    			| '2xlarge'
    			| '4xlarge'
    			| '8xlarge'
    			| '12xlarge'
    			| '16xlarge'
    			| '24xlarge'
    			| '24xlarge_optimized_memory'
    			| '24xlarge_optimized_cpu'
    			| '24xlarge_high_memory'
    			| '48xlarge'
    			| '48xlarge_optimized_memory'
    			| '48xlarge_optimized_cpu'
    			| '48xlarge_high_memory'
    		release_channel?: 'internal' | 'alpha' | 'beta' | 'ga' | 'withdrawn' | 'preview'
    		postgres_engine?: '15' | '17' | '17-oriole'
    		secrets?: {}
    	}
    ) {
    	const url = new URL(`https://api.supabase.com/v1/projects/${ref}/branches`)
    
    	const response = await fetch(url, {
    		method: 'POST',
    		headers: {
    			'Content-Type': 'application/json',
    			Authorization: 'Bearer ' + auth.key
    		},
    		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