0

Create a database

by
Published Oct 17, 2025
Script qovery Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Create a database
4
 *
5
 */
6
export async function main(auth: RT.Qovery, environmentId: string, body: Body) {
7
	const url = new URL(`https://api.qovery.com/environment/${environmentId}/database`)
8

9
	const response = await fetch(url, {
10
		method: 'POST',
11
		headers: {
12
			'Content-Type': 'application/json',
13
			Authorization: 'Token ' + auth.apiKey
14
		},
15
		body: JSON.stringify(body)
16
	})
17
	if (!response.ok) {
18
		const text = await response.text()
19
		throw new Error(`${response.status} ${text}`)
20
	}
21
	return await response.json()
22
}
23

24
/* eslint-disable */
25
/**
26
 * This file was automatically generated by json-schema-to-typescript.
27
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
28
 * and run json-schema-to-typescript to regenerate this file.
29
 */
30

31
export interface Body {
32
	/**
33
	 * name is case insensitive
34
	 */
35
	name: string
36
	/**
37
	 * give a description to this database
38
	 */
39
	description?: string
40
	type: 'MONGODB' | 'MYSQL' | 'POSTGRESQL' | 'REDIS'
41
	version: string
42
	mode: 'CONTAINER' | 'MANAGED'
43
	accessibility?: 'PRIVATE' | 'PUBLIC'
44
	/**
45
	 * unit is millicores (m). 1000m = 1 cpu
46
	 * This field will be ignored for managed DB (instance type will be used instead).
47
	 *
48
	 */
49
	cpu?: number
50
	/**
51
	 * Database instance type to be used for this database. The list of values can be retrieved via the endpoint /{CloudProvider}/managedDatabase/instanceType/{region}/{dbType}. This field SHOULD NOT be set for container DB.
52
	 */
53
	instance_type?: string
54
	/**
55
	 * unit is MB. 1024 MB = 1GB
56
	 * This field will be ignored for managed DB (instance type will be used instead).
57
	 * Default value is linked to the database type:
58
	 * - MANAGED: `100`
59
	 * - CONTAINER
60
	 *   - POSTGRES: `100`
61
	 *   - REDIS: `100`
62
	 *   - MYSQL: `512`
63
	 *   - MONGODB: `256`
64
	 *
65
	 */
66
	memory?: number
67
	/**
68
	 * unit is GB
69
	 */
70
	storage?: number
71
	annotations_groups?: {
72
		id: string
73
		[k: string]: unknown
74
	}[]
75
	labels_groups?: {
76
		id: string
77
		[k: string]: unknown
78
	}[]
79
	/**
80
	 * Icon URI representing the database.
81
	 */
82
	icon_uri?: string
83
	[k: string]: unknown
84
}
85