//native
type Neondb = {
apiKey: string
}
/**
* Create a branch
* Creates a branch in the specified project.
*/
export async function main(
auth: Neondb,
project_id: string,
body: {
endpoints?: {
type: 'read_only' | 'read_write'
autoscaling_limit_min_cu?: number
autoscaling_limit_max_cu?: number
provisioner?: string
suspend_timeout_seconds?: number
}[]
branch?: {
parent_id?: string
name?: string
parent_lsn?: string
parent_timestamp?: string
protected?: false | true
archived?: false | true
schema_initialization_type?: 'empty'
}
} & { annotation_value?: {} }
) {
const url = new URL(`https://console.neon.tech/api/v2/projects/${project_id}/branches`)
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + auth.apiKey
},
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 428 days ago