Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: move column privileges to query route (#35560)

Julien Goux8b45671ff6e9
diff --git a/apps/studio/data/privileges/column-privileges-grant-mutation.ts b/apps/studio/data/privileges/column-privileges-grant-mutation.ts
index 6b229859b54..e1e6933c593 100644
--- a/apps/studio/data/privileges/column-privileges-grant-mutation.ts
+++ b/apps/studio/data/privileges/column-privileges-grant-mutation.ts
@@ -1,10 +1,10 @@
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
import { toast } from 'sonner'
-
import type { components } from 'data/api'
-import { handleError, post } from 'data/fetchers'
import type { ResponseError } from 'types'
import { privilegeKeys } from './keys'
+import pgMeta from '@supabase/pg-meta'
+import { executeSql } from 'data/sql/execute-sql-query'
export type ColumnPrivilegesGrant = components['schemas']['GrantColumnPrivilegesBody']
@@ -19,21 +19,23 @@ export async function grantColumnPrivileges({
connectionString,
grants,
}: ColumnPrivilegesGrantVariables) {
- const headers = new Headers()
- if (connectionString) headers.set('x-connection-encrypted', connectionString)
+ const { sql } = pgMeta.columnPrivileges.grant(
+ grants.map((g) => ({
+ columnId: g.column_id,
+ grantee: g.grantee,
+ privilegeType: g.privilege_type,
+ isGrantable: g.is_grantable,
+ }))
+ )
- const { data, error } = await post('/platform/pg-meta/{ref}/column-privileges', {
- params: {
- path: { ref: projectRef },
- // this is needed to satisfy the typescript, but it doesn't pass the actual header
- header: { 'x-connection-encrypted': connectionString! },
- },
- body: grants,
- headers,
+ const { result } = await executeSql({
+ projectRef,
+ connectionString,
+ sql,
+ queryKey: ['column-privileges', 'grant'],
})
- if (error) handleError(error)
- return data
+ return result
}
type ColumnPrivilegesGrantData = Awaited<ReturnType<typeof grantColumnPrivileges>>
diff --git a/apps/studio/data/privileges/column-privileges-revoke-mutation.ts b/apps/studio/data/privileges/column-privileges-revoke-mutation.ts
index 8406947df50..2a0d94043ce 100644
--- a/apps/studio/data/privileges/column-privileges-revoke-mutation.ts
+++ b/apps/studio/data/privileges/column-privileges-revoke-mutation.ts
@@ -1,9 +1,9 @@
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
import { toast } from 'sonner'
-
import type { components } from 'data/api'
-import { del, handleError } from 'data/fetchers'
import type { ResponseError } from 'types'
+import pgMeta from '@supabase/pg-meta'
+import { executeSql } from 'data/sql/execute-sql-query'
import { privilegeKeys } from './keys'
export type ColumnPrivilegesRevoke = components['schemas']['RevokeColumnPrivilegesBody']
@@ -19,21 +19,22 @@ export async function revokeColumnPrivileges({
connectionString,
revokes,
}: ColumnPrivilegesRevokeVariables) {
- const headers = new Headers()
- if (connectionString) headers.set('x-connection-encrypted', connectionString)
+ const { sql } = pgMeta.columnPrivileges.revoke(
+ revokes.map((r) => ({
+ columnId: r.column_id,
+ grantee: r.grantee,
+ privilegeType: r.privilege_type,
+ }))
+ )
- const { data, error } = await del('/platform/pg-meta/{ref}/column-privileges', {
- params: {
- path: { ref: projectRef },
- // this is needed to satisfy the typescript, but it doesn't pass the actual header
- header: { 'x-connection-encrypted': connectionString! },
- },
- body: revokes,
- headers,
+ const { result } = await executeSql({
+ projectRef,
+ connectionString,
+ sql,
+ queryKey: ['column-privileges', 'revoke'],
})
- if (error) handleError(error)
- return data
+ return result
}
type ColumnPrivilegesRevokeData = Awaited<ReturnType<typeof revokeColumnPrivileges>>