Skip to content

Commit 4bd28ee

Browse files
authored
fix(api): set x-pg-application-name for dashboard (supabase#37048)
chore(api): set x-pg-application-name for dashboard
1 parent 78419c7 commit 4bd28ee

File tree

14 files changed

+132
-12
lines changed

14 files changed

+132
-12
lines changed

apps/studio/data/database-extensions/database-extensions-query.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { databaseExtensionsKeys } from './keys'
55
import { components } from 'api-types'
66
import { useSelectedProject } from 'hooks/misc/useSelectedProject'
77
import { PROJECT_STATUS } from 'lib/constants'
8+
import { DEFAULT_PLATFORM_APPLICATION_NAME } from '@supabase/pg-meta/src/constants'
89

910
export type DatabaseExtension = components['schemas']['PostgresExtension']
1011

@@ -27,6 +28,7 @@ export async function getDatabaseExtensions(
2728
params: {
2829
header: {
2930
'x-connection-encrypted': connectionString!,
31+
'x-pg-application-name': DEFAULT_PLATFORM_APPLICATION_NAME,
3032
},
3133
path: {
3234
ref: projectRef,

apps/studio/data/database-policies/database-policies-query.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useSelectedProject } from 'hooks/misc/useSelectedProject'
55
import { PROJECT_STATUS } from 'lib/constants'
66
import type { ResponseError } from 'types'
77
import { databasePoliciesKeys } from './keys'
8+
import { DEFAULT_PLATFORM_APPLICATION_NAME } from '@supabase/pg-meta/src/constants'
89

910
export type DatabasePoliciesVariables = {
1011
projectRef?: string
@@ -24,7 +25,10 @@ export async function getDatabasePolicies(
2425

2526
const { data, error } = await get('/platform/pg-meta/{ref}/policies', {
2627
params: {
27-
header: { 'x-connection-encrypted': connectionString! },
28+
header: {
29+
'x-connection-encrypted': connectionString!,
30+
'x-pg-application-name': DEFAULT_PLATFORM_APPLICATION_NAME,
31+
},
2832
path: { ref: projectRef },
2933
query: {
3034
included_schemas: schema || '',

apps/studio/data/database-publications/database-publications-query.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { UseQueryOptions, useQuery } from '@tanstack/react-query'
22
import { get, handleError } from 'data/fetchers'
33
import type { ResponseError } from 'types'
44
import { databasePublicationsKeys } from './keys'
5+
import { DEFAULT_PLATFORM_APPLICATION_NAME } from '@supabase/pg-meta/src/constants'
56

67
export type DatabasePublicationsVariables = {
78
projectRef?: string
@@ -21,6 +22,7 @@ export async function getDatabasePublications(
2122
params: {
2223
header: {
2324
'x-connection-encrypted': connectionString!,
25+
'x-pg-application-name': DEFAULT_PLATFORM_APPLICATION_NAME,
2426
},
2527
path: {
2628
ref: projectRef,

apps/studio/data/database-triggers/database-triggers-query.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useQuery, UseQueryOptions } from '@tanstack/react-query'
22
import { get, handleError } from 'data/fetchers'
33
import type { ResponseError } from 'types'
44
import { databaseTriggerKeys } from './keys'
5+
import { DEFAULT_PLATFORM_APPLICATION_NAME } from '@supabase/pg-meta/src/constants'
56

67
export type DatabaseTriggersVariables = {
78
projectRef?: string
@@ -19,7 +20,10 @@ export async function getDatabaseTriggers(
1920

2021
const { data, error } = await get('/platform/pg-meta/{ref}/triggers', {
2122
params: {
22-
header: { 'x-connection-encrypted': connectionString! },
23+
header: {
24+
'x-connection-encrypted': connectionString!,
25+
'x-pg-application-name': DEFAULT_PLATFORM_APPLICATION_NAME,
26+
},
2327
path: { ref: projectRef },
2428
query: undefined as any,
2529
},

apps/studio/data/enumerated-types/enumerated-types-query.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { components } from 'data/api'
44
import { get, handleError } from 'data/fetchers'
55
import type { ResponseError } from 'types'
66
import { enumeratedTypesKeys } from './keys'
7+
import { DEFAULT_PLATFORM_APPLICATION_NAME } from '@supabase/pg-meta/src/constants'
78

89
export type EnumeratedTypesVariables = {
910
projectRef?: string
@@ -23,7 +24,10 @@ export async function getEnumeratedTypes(
2324

2425
const { data, error } = await get('/platform/pg-meta/{ref}/types', {
2526
params: {
26-
header: { 'x-connection-encrypted': connectionString! },
27+
header: {
28+
'x-connection-encrypted': connectionString!,
29+
'x-pg-application-name': DEFAULT_PLATFORM_APPLICATION_NAME,
30+
},
2731
path: { ref: projectRef },
2832
},
2933
headers: Object.fromEntries(headers),

apps/studio/data/fetchers.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { API_URL } from 'lib/constants'
66
import { getAccessToken } from 'lib/gotrue'
77
import { uuidv4 } from 'lib/helpers'
88
import { ResponseError } from 'types'
9-
// generated from openapi-typescript
10-
import type { paths } from './api'
9+
import type { paths } from './api' // generated from openapi-typescript
10+
import { DEFAULT_PLATFORM_APPLICATION_NAME } from '@supabase/pg-meta/src/constants'
1111

1212
const DEFAULT_HEADERS = { Accept: 'application/json' }
1313

@@ -73,6 +73,9 @@ function pgMetaGuard(request: Request) {
7373
retryAfterHeader ? parseInt(retryAfterHeader) : undefined
7474
)
7575
}
76+
if (!request.headers.get('x-pg-application-name')) {
77+
request.headers.set('x-pg-application-name', DEFAULT_PLATFORM_APPLICATION_NAME)
78+
}
7679
}
7780
return request
7881
}

apps/studio/data/foreign-tables/foreign-tables-query.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { PostgresView } from '@supabase/postgres-meta'
44
import { get, handleError } from 'data/fetchers'
55
import type { ResponseError } from 'types'
66
import { foreignTableKeys } from './keys'
7+
import { DEFAULT_PLATFORM_APPLICATION_NAME } from '@supabase/pg-meta/src/constants'
78

89
export type ForeignTablesVariables = {
910
projectRef?: string
@@ -22,7 +23,10 @@ export async function getForeignTables(
2223

2324
const { data, error } = await get('/platform/pg-meta/{ref}/foreign-tables', {
2425
params: {
25-
header: { 'x-connection-encrypted': connectionString! },
26+
header: {
27+
'x-connection-encrypted': connectionString!,
28+
'x-pg-application-name': DEFAULT_PLATFORM_APPLICATION_NAME,
29+
},
2630
path: { ref: projectRef },
2731
query: {
2832
included_schemas: schema || '',

apps/studio/data/materialized-views/materialized-views-query.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { PostgresMaterializedView } from '@supabase/postgres-meta'
44
import { get, handleError } from 'data/fetchers'
55
import type { ResponseError } from 'types'
66
import { materializedViewKeys } from './keys'
7+
import { DEFAULT_PLATFORM_APPLICATION_NAME } from '@supabase/pg-meta/src/constants'
78

89
export type MaterializedViewsVariables = {
910
projectRef?: string
@@ -22,7 +23,10 @@ export async function getMaterializedViews(
2223

2324
const { data, error } = await get('/platform/pg-meta/{ref}/materialized-views', {
2425
params: {
25-
header: { 'x-connection-encrypted': connectionString! },
26+
header: {
27+
'x-connection-encrypted': connectionString!,
28+
'x-pg-application-name': DEFAULT_PLATFORM_APPLICATION_NAME,
29+
},
2630
path: { ref: projectRef },
2731
query: {
2832
included_schemas: schema || '',

apps/studio/data/privileges/column-privileges-query.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { components } from 'data/api'
44
import { get, handleError } from 'data/fetchers'
55
import type { ResponseError } from 'types'
66
import { privilegeKeys } from './keys'
7+
import { DEFAULT_PLATFORM_APPLICATION_NAME } from '@supabase/pg-meta/src/constants'
78

89
export type ColumnPrivilegesVariables = {
910
projectRef?: string
@@ -25,7 +26,10 @@ export async function getColumnPrivileges(
2526
params: {
2627
path: { ref: projectRef },
2728
// this is needed to satisfy the typescript, but it doesn't pass the actual header
28-
header: { 'x-connection-encrypted': connectionString! },
29+
header: {
30+
'x-connection-encrypted': connectionString!,
31+
'x-pg-application-name': DEFAULT_PLATFORM_APPLICATION_NAME,
32+
},
2933
},
3034
signal,
3135
headers,

apps/studio/data/sql/execute-sql-query.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from 'lib/role-impersonation'
1010
import type { ResponseError } from 'types'
1111
import { sqlKeys } from './keys'
12+
import { DEFAULT_PLATFORM_APPLICATION_NAME } from '@supabase/pg-meta/src/constants'
1213

1314
export type ExecuteSqlVariables = {
1415
projectRef?: string
@@ -73,7 +74,12 @@ export async function executeSql<T = any>(
7374
const result = await post('/platform/pg-meta/{ref}/query', {
7475
signal,
7576
params: {
76-
header: { 'x-connection-encrypted': connectionString ?? '' },
77+
header: {
78+
'x-connection-encrypted': connectionString ?? '',
79+
'x-pg-application-name': isStatementTimeoutDisabled
80+
? 'supabase/dashboard-query-editor'
81+
: DEFAULT_PLATFORM_APPLICATION_NAME,
82+
},
7783
path: { ref: projectRef },
7884
// @ts-expect-error: This is just a client side thing to identify queries better
7985
query: {

0 commit comments

Comments
 (0)