Create a database branch
One script reply has been approved by the moderators Verified

Creates a database branch from the specified project.

Created by hugo697 151 days ago
Submitted by hugo697 Bun
Verified 151 days ago
1
//native
2
type Supabase = {
3
	key: string
4
}
5
/**
6
 * Create a database branch
7
 * Creates a database branch from the specified project.
8
 */
9
export async function main(
10
	auth: Supabase,
11
	ref: string,
12
	body: {
13
		branch_name: string
14
		git_branch?: string
15
		persistent?: false | true
16
		region?: string
17
		desired_instance_size?:
18
			| 'pico'
19
			| 'nano'
20
			| 'micro'
21
			| 'small'
22
			| 'medium'
23
			| 'large'
24
			| 'xlarge'
25
			| '2xlarge'
26
			| '4xlarge'
27
			| '8xlarge'
28
			| '12xlarge'
29
			| '16xlarge'
30
			| '24xlarge'
31
			| '24xlarge_optimized_memory'
32
			| '24xlarge_optimized_cpu'
33
			| '24xlarge_high_memory'
34
			| '48xlarge'
35
			| '48xlarge_optimized_memory'
36
			| '48xlarge_optimized_cpu'
37
			| '48xlarge_high_memory'
38
		release_channel?: 'internal' | 'alpha' | 'beta' | 'ga' | 'withdrawn' | 'preview'
39
		postgres_engine?: '15' | '17' | '17-oriole'
40
		secrets?: {}
41
	}
42
) {
43
	const url = new URL(`https://api.supabase.com/v1/projects/${ref}/branches`)
44

45
	const response = await fetch(url, {
46
		method: 'POST',
47
		headers: {
48
			'Content-Type': 'application/json',
49
			Authorization: 'Bearer ' + auth.key
50
		},
51
		body: JSON.stringify(body)
52
	})
53
	if (!response.ok) {
54
		const text = await response.text()
55
		throw new Error(`${response.status} ${text}`)
56
	}
57
	return await response.json()
58
}
59