Skip to content

Commit

Permalink
feat(studio): db-pool postgrest config
Browse files Browse the repository at this point in the history
  • Loading branch information
soedirgo committed Apr 18, 2024
1 parent 08a0a86 commit e9828a3
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 13 deletions.
Expand Up @@ -40,7 +40,7 @@ const PostgrestConfig = () => {
)

const formId = 'project-postgres-config'
const initialValues = { db_schema: '', max_rows: '', db_extra_search_path: '' }
const initialValues = { db_schema: '', max_rows: '', db_extra_search_path: '', db_pool: '' }

const updateConfig = async (updatedConfig: typeof initialValues) => {
if (!projectRef) return console.error('Project ref is required')
Expand All @@ -49,6 +49,7 @@ const PostgrestConfig = () => {
dbSchema: updatedConfig.db_schema,
maxRows: updatedConfig.max_rows,
dbExtraSearchPath: updatedConfig.db_extra_search_path,
dbPool: updatedConfig.db_pool || null,
})
}

Expand Down Expand Up @@ -83,6 +84,7 @@ const PostgrestConfig = () => {
db_schema: config.db_schema,
max_rows: config.max_rows,
db_extra_search_path: config.db_extra_search_path ?? '',
db_pool: config.db_pool || null,
}
resetForm({ values, initialValues: values })
}
Expand Down Expand Up @@ -177,6 +179,17 @@ const PostgrestConfig = () => {
/>
</FormSectionContent>
</FormSection>
<FormSection header={<FormSectionLabel>Pool size</FormSectionLabel>}>
<FormSectionContent loading={false}>
<InputNumber
id="db_pool"
size="small"
disabled={!canUpdatePostgrestConfig}
descriptionText="Number of maximum connections to keep open in the Data API server's database pool. Unset to let it be configured automatically based on compute size."
placeholder="Configured automatically based on compute size"
/>
</FormSectionContent>
</FormSection>
</>
)}
</FormPanel>
Expand Down
58 changes: 46 additions & 12 deletions apps/studio/data/api.d.ts
Expand Up @@ -637,7 +637,7 @@ export interface paths {
}
'/platform/projects/{ref}/analytics/warehouse/query': {
/** Lists project's warehouse queries from logflare */
get: operations['QueryController_runQuery']
get: operations['WarehouseQueryController_runQuery']
}
'/platform/projects/{ref}/config/pgbouncer': {
/** Gets project's pgbouncer config */
Expand Down Expand Up @@ -1473,7 +1473,7 @@ export interface paths {
}
'/v0/projects/{ref}/analytics/warehouse/query': {
/** Lists project's warehouse queries from logflare */
get: operations['QueryController_runQuery']
get: operations['WarehouseQueryController_runQuery']
}
'/v0/projects/{ref}/config/pgbouncer': {
/** Gets project's pgbouncer config */
Expand Down Expand Up @@ -4039,13 +4039,15 @@ export interface components {
}
UpdatePostgrestConfigBody: {
max_rows?: number
db_pool?: number
db_extra_search_path?: string
db_schema?: string
}
V1PostgrestConfigResponse: {
max_rows: number
db_schema: string
db_extra_search_path: string
max_rows: number | null
db_pool: number | null
db_schema: string | null
db_extra_search_path: string | null
}
PostgresConfigResponse: {
statement_timeout?: string
Expand Down Expand Up @@ -4959,9 +4961,10 @@ export interface components {
root_key: string
}
PostgrestConfigWithJWTSecretResponse: {
max_rows: number
db_schema: string
db_extra_search_path: string
max_rows: number | null
db_pool: number | null
db_schema: string | null
db_extra_search_path: string | null
jwt_secret?: string
}
V1ProjectRefResponse: {
Expand Down Expand Up @@ -8184,22 +8187,32 @@ export interface operations {
}
}
}
/** Lists project's warehouse queries from logflare */
/** Run sql query */
QueryController_runQuery: {
parameters: {
header: {
'x-connection-encrypted': string
}
path: {
/** @description Project ref */
ref: string
}
}
requestBody: {
content: {
'application/json': components['schemas']['RunQueryBody']
}
}
responses: {
200: {
content: never
201: {
content: {
'application/json': Record<string, never>
}
}
403: {
content: never
}
/** @description Failed to fetch warehouse endpoints */
/** @description Failed to run sql query */
500: {
content: never
}
Expand Down Expand Up @@ -10228,6 +10241,27 @@ export interface operations {
}
}
}
/** Lists project's warehouse queries from logflare */
WarehouseQueryController_runQuery: {
parameters: {
path: {
/** @description Project ref */
ref: string
}
}
responses: {
200: {
content: never
}
403: {
content: never
}
/** @description Failed to fetch warehouse endpoints */
500: {
content: never
}
}
}
/** Gets project's pgbouncer config */
PgbouncerConfigController_getPgbouncerConfig: {
parameters: {
Expand Down
1 change: 1 addition & 0 deletions apps/studio/data/config/project-postgrest-config-query.ts
Expand Up @@ -13,6 +13,7 @@ export type ProjectPostgrestConfigResponse = {
db_schema: string
db_anon_role: string
db_extra_search_path: string
db_pool: number | null
jwt_secret: string
}

Expand Down
Expand Up @@ -11,18 +11,21 @@ export type ProjectPostgrestConfigUpdateVariables = {
dbSchema: string
maxRows: string
dbExtraSearchPath: string
dbPool: string | null
}

export async function updateProjectPostgrestConfig({
projectRef,
dbSchema,
maxRows,
dbExtraSearchPath,
dbPool,
}: ProjectPostgrestConfigUpdateVariables) {
const response = await patch(`${API_URL}/projects/${projectRef}/config/postgrest`, {
db_schema: dbSchema,
max_rows: maxRows,
db_extra_search_path: dbExtraSearchPath,
db_pool: dbPool,
})

if (response.error) throw response.error
Expand Down

0 comments on commit e9828a3

Please sign in to comment.