Skip to content

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

[FE-2792] feat(studio): unify table exposure check on RLS policies page (#45041)

Alaister Youngd272c15d8d89
diff --git a/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/PolicyTableRow.utils.test.ts b/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/PolicyTableRow.utils.test.ts
new file mode 100644
index 00000000000..d2722dca028
--- /dev/null
+++ b/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/PolicyTableRow.utils.test.ts
@@ -0,0 +1,184 @@
+import { describe, expect, it } from 'vitest'
+
+import { getTableAdmonitionMessage, getTableDataApiStatus } from './PolicyTableRow.utils'
+import type { TableApiAccessData } from '@/data/privileges/table-api-access-query'
+import type { ApiPrivilegesByRole } from '@/lib/data-api-types'
+
+const FULL_PRIVILEGES: ApiPrivilegesByRole = {
+ anon: ['SELECT', 'INSERT', 'UPDATE', 'DELETE'],
+ authenticated: ['SELECT', 'INSERT', 'UPDATE', 'DELETE'],
+ service_role: ['SELECT', 'INSERT', 'UPDATE', 'DELETE'],
+}
+
+const PARTIAL_PRIVILEGES: ApiPrivilegesByRole = {
+ anon: ['SELECT'],
+ authenticated: [],
+ service_role: ['SELECT', 'INSERT', 'UPDATE', 'DELETE'],
+}
+
+const grantedAccess: TableApiAccessData = {
+ apiAccessType: 'access',
+ grantStatus: 'granted',
+ privileges: FULL_PRIVILEGES,
+}
+
+const customAccess: TableApiAccessData = {
+ apiAccessType: 'access',
+ grantStatus: 'custom',
+ privileges: PARTIAL_PRIVILEGES,
+}
+
+const noGrants: TableApiAccessData = { apiAccessType: 'exposed-schema-no-grants' }
+const schemaNotExposedData: TableApiAccessData = { apiAccessType: 'none' }
+
+describe('getTableDataApiStatus', () => {
+ it('returns schema-not-exposed when the schema is not in the exposed list', () => {
+ const status = getTableDataApiStatus({
+ isSchemaExposed: false,
+ apiAccessData: grantedAccess,
+ isRLSEnabled: true,
+ policiesCount: 1,
+ })
+ expect(status).toBe('schema-not-exposed')
+ })
+
+ it('returns no-grants when schema is exposed but no API roles have privileges', () => {
+ const status = getTableDataApiStatus({
+ isSchemaExposed: true,
+ apiAccessData: noGrants,
+ isRLSEnabled: true,
+ policiesCount: 0,
+ })
+ expect(status).toBe('no-grants')
+ })
+
+ it('returns custom-grants for partial/non-standard grants — even if RLS is off', () => {
+ const status = getTableDataApiStatus({
+ isSchemaExposed: true,
+ apiAccessData: customAccess,
+ isRLSEnabled: false,
+ policiesCount: 0,
+ })
+ expect(status).toBe('custom-grants')
+ })
+
+ it('returns publicly-readable when fully granted and RLS is off', () => {
+ const status = getTableDataApiStatus({
+ isSchemaExposed: true,
+ apiAccessData: grantedAccess,
+ isRLSEnabled: false,
+ policiesCount: 3,
+ })
+ expect(status).toBe('publicly-readable')
+ })
+
+ it('returns locked-by-rls when fully granted + RLS on + no policies', () => {
+ const status = getTableDataApiStatus({
+ isSchemaExposed: true,
+ apiAccessData: grantedAccess,
+ isRLSEnabled: true,
+ policiesCount: 0,
+ })
+ expect(status).toBe('locked-by-rls')
+ })
+
+ it('returns secured when fully granted + RLS on + policies exist', () => {
+ const status = getTableDataApiStatus({
+ isSchemaExposed: true,
+ apiAccessData: grantedAccess,
+ isRLSEnabled: true,
+ policiesCount: 2,
+ })
+ expect(status).toBe('secured')
+ })
+
+ it('returns unknown when apiAccessData is still loading or errored', () => {
+ // apiAccessData is undefined during loading AND on query error (isPending flips false
+ // but data stays undefined). We must not fall through to 'schema-not-exposed' — that
+ // would tell the user to reconfigure API settings for a schema that is in fact exposed.
+ const status = getTableDataApiStatus({
+ isSchemaExposed: true,
+ apiAccessData: undefined,
+ isRLSEnabled: true,
+ policiesCount: 0,
+ })
+ expect(status).toBe('unknown')
+ })
+
+ it('returns unknown when apiAccessData reports apiAccessType=none on an exposed schema', () => {
+ // Defensive: the query shouldn't emit apiAccessType=none when schema is exposed,
+ // but if it does we still don't want the false "schema not exposed" admonition.
+ const status = getTableDataApiStatus({
+ isSchemaExposed: true,
+ apiAccessData: schemaNotExposedData,
+ isRLSEnabled: true,
+ policiesCount: 0,
+ })
+ expect(status).toBe('unknown')
+ })
+
+ it('isSchemaExposed=false wins over any apiAccessData value', () => {
+ const status = getTableDataApiStatus({
+ isSchemaExposed: false,
+ apiAccessData: noGrants,
+ isRLSEnabled: true,
+ policiesCount: 0,
+ })
+ expect(status).toBe('schema-not-exposed')
+ })
+
+ it('custom-grants wins over RLS state — we never claim public-readable for partial grants', () => {
+ const rlsOff = getTableDataApiStatus({
+ isSchemaExposed: true,
+ apiAccessData: customAccess,
+ isRLSEnabled: false,
+ policiesCount: 0,
+ })
+ const rlsOnNoPolicies = getTableDataApiStatus({
+ isSchemaExposed: true,
+ apiAccessData: customAccess,
+ isRLSEnabled: true,
+ policiesCount: 0,
+ })
+ expect(rlsOff).toBe('custom-grants')
+ expect(rlsOnNoPolicies).toBe('custom-grants')
+ })
+})
+
+describe('getTableAdmonitionMessage', () => {
+ it('returns the custom-grants copy', () => {
+ expect(getTableAdmonitionMessage('custom-grants')).toBe(
+ 'This table has custom Data API permissions — access may be restricted for some roles or operations.'
+ )
+ })
+
+ it('returns the no-grants copy', () => {
+ expect(getTableAdmonitionMessage('no-grants')).toBe(
+ 'This table cannot be accessed via the Data API. Enable access in your project’s Data API settings.'
+ )
+ })
+
+ it('returns the publicly-readable copy', () => {
+ expect(getTableAdmonitionMessage('publicly-readable')).toBe(
+ 'This table can be accessed by anyone via the Data API as RLS is disabled.'
+ )
+ })
+
+ it('returns the locked-by-rls copy', () => {
+ expect(getTableAdmonitionMessage('locked-by-rls')).toBe(
+ 'No data will be returned via the Data API as no RLS policies exist on this table.'
+ )
+ })
+
+ it('returns null for secured — no admonition needed', () => {
+ expect(getTableAdmonitionMessage('secured')).toBeNull()
+ })
+
+ it('returns null for schema-not-exposed — handled by a separate admonition with a link', () => {
+ expect(getTableAdmonitionMessage('schema-not-exposed')).toBeNull()
+ })
+
+ it('returns null for unknown — caller should stay silent during loading/errored state', () => {
+ expect(getTableAdmonitionMessage('unknown')).toBeNull()
+ })
+})
diff --git a/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/PolicyTableRow.utils.ts b/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/PolicyTableRow.utils.ts
index 98bfcf60729..4c58e9ed863 100644
--- a/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/PolicyTableRow.utils.ts
+++ b/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/PolicyTableRow.utils.ts
@@ -1,5 +1,66 @@
import { PostgresPolicy } from '@supabase/postgres-meta'
+import type { TableApiAccessData } from '@/data/privileges/table-api-access-query'
+
+/**
+ * Single classifier for the RLS page's per-table admonition state. Shares the
+ * "granted / custom / revoked" grant semantics used by the Data API settings
+ * page's ExposedTableSelector so the two views agree on what counts as exposed.
+ */
+export type TableDataApiStatus =
+ | 'schema-not-exposed' // schema isn't in the PostgREST exposed list
+ | 'no-grants' // schema exposed, no API roles have any privileges (revoked)
+ | 'custom-grants' // schema exposed, partial / non-standard grants
+ | 'publicly-readable' // fully granted + RLS disabled (dangerous)
+ | 'locked-by-rls' // fully granted + RLS enabled, no policies
+ | 'secured' // fully granted + RLS enabled, policies exist
+ | 'unknown' // privileges query is still loading or errored — caller should stay silent
+
+export function getTableDataApiStatus({
+ isSchemaExposed,
+ apiAccessData,
+ isRLSEnabled,
+ policiesCount,
+}: {
+ isSchemaExposed: boolean
+ apiAccessData: TableApiAccessData | undefined
+ isRLSEnabled: boolean
+ policiesCount: number
+}): TableDataApiStatus {
+ if (!isSchemaExposed) return 'schema-not-exposed'
+ if (apiAccessData?.apiAccessType === 'exposed-schema-no-grants') return 'no-grants'
+ if (apiAccessData?.apiAccessType === 'access') {
+ if (apiAccessData.grantStatus === 'custom') return 'custom-grants'
+ if (!isRLSEnabled) return 'publicly-readable'
+ if (policiesCount === 0) return 'locked-by-rls'
+ return 'secured'
+ }
+ // Schema is exposed but the privileges query hasn't resolved (still loading
+ // or errored). We return 'unknown' rather than 'schema-not-exposed' so the
+ // caller doesn't falsely tell the user to reconfigure API settings.
+ return 'unknown'
+}
+
+/**
+ * Returns the copy for the in-row admonition, or null when the row needs no
+ * admonition (the "everything is fine" `secured` case and the orthogonal
+ * `schema-not-exposed` case which is rendered separately with a link).
+ */
+export function getTableAdmonitionMessage(status: TableDataApiStatus): string | null {
+ switch (status) {
+ case 'custom-grants':
+ return 'This table has custom Data API permissions — access may be restricted for some roles or operations.'
+ case 'no-grants':
+ return 'This table cannot be accessed via the Data API. Enable access in your project’s Data API settings.'
+ case 'publicly-readable':
+ return 'This table can be accessed by anyone via the Data API as RLS is disabled.'
+ case 'locked-by-rls':
+ return 'No data will be returned via the Data API as no RLS policies exist on this table.'
+ default:
+ return null
+ }
+}
+
export const generatePolicyUpdateSQL = (policy: PostgresPolicy) => {
let expression = ''
if (policy.definition !== null && policy.definition !== undefined) {
diff --git a/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/index.tsx b/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/index.tsx
index 8a41aa1b98b..63e1327dee7 100644
--- a/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/index.tsx
+++ b/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/index.tsx
@@ -19,10 +19,11 @@ import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
import { usePoliciesData } from '../PoliciesDataContext'
import { PolicyRow } from './PolicyRow'
import type { PolicyTable } from './PolicyTableRow.types'
+import { getTableAdmonitionMessage, getTableDataApiStatus } from './PolicyTableRow.utils'
import { PolicyTableRowHeader } from './PolicyTableRowHeader'
import AlertError from '@/components/ui/AlertError'
import { InlineLink } from '@/components/ui/InlineLink'
-import { useTablesRolesAccessQuery } from '@/data/tables/tables-roles-access-query'
+import { useTableApiAccessQuery } from '@/data/privileges/table-api-access-query'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
export interface PolicyTableRowProps {
@@ -52,57 +53,48 @@ const PolicyTableRowComponent = ({
[getPoliciesForTable, table.schema, table.name]
)
- // [Joshen] Changes here are so that warnings are more accurate and granular instead of purely relying if RLS is disabled or enabled
- // The following scenarios are technically okay if the table has RLS disabled, in which it won't be publicly readable / writable
- // - If the schema is not exposed through the API via Postgrest
- // - If the anon and authenticated roles do not have access to the table
- // Ideally we should just rely on the security lints as the source of truth, but the security lints currently have limitations
- // - They only consider the public schema
- // - They do not consider roles
- // Eventually if the security lints are able to cover those, we can look to using them as the source of truth instead then
- const isRLSEnabled = table.rls_enabled
- const isTableExposedThroughAPI = useMemo(
- () => exposedSchemas.has(table.schema),
- [exposedSchemas, table.schema]
+ // [Joshen] Classification is more granular than "RLS on/off" alone — it also considers
+ // schema exposure and whether anon/authenticated/service_role actually have grants.
+ // Ideally we'd rely on the security lints, but they only look at the public schema and
+ // ignore roles. Once the lints cover both, we can switch to them as the source of truth.
+ const tableNames = useMemo(() => [table.name], [table.name])
+ const {
+ data: apiAccessMap,
+ isPending: isLoadingRolesAccess,
+ isError: isRolesAccessError,
+ } = useTableApiAccessQuery({
+ projectRef: project?.ref,
+ connectionString: project?.connectionString,
+ schemaName: table.schema,
+ tableNames,
+ })
+
+ const status = useMemo(
+ () =>
+ getTableDataApiStatus({
+ isSchemaExposed: exposedSchemas.has(table.schema),
+ apiAccessData: apiAccessMap?.[table.name],
+ isRLSEnabled: table.rls_enabled,
+ policiesCount: policies.length,
+ }),
+ [exposedSchemas, apiAccessMap, table.schema, table.name, table.rls_enabled, policies.length]
)
- const { data: tablesWithAnonAuthAccess = new Set(), isLoading: isLoadingRolesAccess } =
- useTablesRolesAccessQuery({
- projectRef: project?.ref,
- connectionString: project?.connectionString,
- schema: table.schema,
- })
-
- const hasAnonAuthenticatedRolesAccess = tablesWithAnonAuthAccess.has(table.name)
- const hasApiAccess = isTableExposedThroughAPI && hasAnonAuthenticatedRolesAccess
- const isPubliclyReadableWritable = !isRLSEnabled && hasApiAccess
- const rlsEnabledNoPolicies = isRLSEnabled && hasApiAccess && policies.length === 0
- const isApiDisabledDueToRoles = isTableExposedThroughAPI && !hasAnonAuthenticatedRolesAccess
+ const hasApiAccess =
+ status === 'publicly-readable' || status === 'locked-by-rls' || status === 'secured'
+ const isPubliclyReadable = status === 'publicly-readable'
+
const isRealtimeSchema = table.schema === 'realtime'
const isRealtimeMessagesTable = isRealtimeSchema && table.name === 'messages'
const isTableLocked = isRealtimeSchema ? !isRealtimeMessagesTable : isLocked
const showPolicies = !isPoliciesLoading && !isPoliciesError && !isLoadingRolesAccess
- const shouldHideHeaderBorder =
- isPubliclyReadableWritable ||
- rlsEnabledNoPolicies ||
- !isTableExposedThroughAPI ||
- isApiDisabledDueToRoles
-
- const admonitionMessage = useMemo(() => {
- if (isPubliclyReadableWritable) {
- return 'This table can be accessed by anyone via the Data API as RLS is disabled.'
- }
- if (isApiDisabledDueToRoles) {
- return 'This table cannot be accessed via the Data API as no permissions exist for the anon or authenticated roles.'
- }
- return 'This table can be accessed via the Data API but no RLS policies exist so no data will be returned.'
- }, [isPubliclyReadableWritable, isApiDisabledDueToRoles])
+ const admonitionMessage = useMemo(() => getTableAdmonitionMessage(status), [status])
return (
- <Card className={cn(isPubliclyReadableWritable && 'border-warning-500')}>
- <CardHeader className={cn('py-3 px-4', shouldHideHeaderBorder && 'border-b-0')}>
+ <Card className={cn(isPubliclyReadable && 'border-warning-500')}>
+ <CardHeader className={cn('py-3 px-4', status !== 'secured' && 'border-b-0')}>
<PolicyTableRowHeader
table={table}
isLocked={isLocked}
@@ -113,7 +105,7 @@ const PolicyTableRowComponent = ({
/>
</CardHeader>
- {!isLoadingRolesAccess && !isTableExposedThroughAPI && (
+ {!isLoadingRolesAccess && !isRolesAccessError && status === 'schema-not-exposed' && (
<Admonition
showIcon={false}
type="warning"
@@ -130,17 +122,15 @@ const PolicyTableRowComponent = ({
</Admonition>
)}
- {!isLoadingRolesAccess &&
- (isPubliclyReadableWritable || rlsEnabledNoPolicies || isApiDisabledDueToRoles) &&
- isTableExposedThroughAPI && (
- <Admonition
- showIcon={false}
- type={isPubliclyReadableWritable ? 'warning' : 'default'}
- className="border-0 border-y rounded-none min-h-12 flex items-center"
- >
- <p>{admonitionMessage}</p>
- </Admonition>
- )}
+ {!isLoadingRolesAccess && !isRolesAccessError && admonitionMessage !== null && (
+ <Admonition
+ showIcon={false}
+ type={isPubliclyReadable ? 'warning' : 'default'}
+ className="border-0 border-y rounded-none min-h-12 flex items-center"
+ >
+ <p>{admonitionMessage}</p>
+ </Admonition>
+ )}
{(isPoliciesLoading || isLoadingRolesAccess) && (
<CardContent>
diff --git a/apps/studio/data/privileges/table-api-access-query.test.ts b/apps/studio/data/privileges/table-api-access-query.test.ts
new file mode 100644
index 00000000000..4491bce02a0
--- /dev/null
+++ b/apps/studio/data/privileges/table-api-access-query.test.ts
@@ -0,0 +1,70 @@
+import { describe, expect, it } from 'vitest'
+
+import { isFullyGranted } from './table-api-access-query'
+import type { ApiPrivilegesByRole } from '@/lib/data-api-types'
+
+const fullPrivileges = (): ApiPrivilegesByRole => ({
+ anon: ['SELECT', 'INSERT', 'UPDATE', 'DELETE'],
+ authenticated: ['SELECT', 'INSERT', 'UPDATE', 'DELETE'],
+ service_role: ['SELECT', 'INSERT', 'UPDATE', 'DELETE'],
+})
+
+describe('isFullyGranted', () => {
+ it('returns true when all 3 API roles have all 4 CRUD privileges', () => {
+ expect(isFullyGranted(fullPrivileges())).toBe(true)
+ })
+
+ it('returns false when anon is missing any CRUD privilege', () => {
+ const privileges = fullPrivileges()
+ privileges.anon = ['SELECT', 'INSERT', 'UPDATE'] // no DELETE
+ expect(isFullyGranted(privileges)).toBe(false)
+ })
+
+ it('returns false when authenticated has no privileges at all', () => {
+ const privileges = fullPrivileges()
+ privileges.authenticated = []
+ expect(isFullyGranted(privileges)).toBe(false)
+ })
+
+ it('returns false when service_role is missing a privilege', () => {
+ const privileges = fullPrivileges()
+ privileges.service_role = ['SELECT', 'INSERT', 'DELETE'] // no UPDATE
+ expect(isFullyGranted(privileges)).toBe(false)
+ })
+
+ it('returns false when every role has only SELECT (partial across the board)', () => {
+ const privileges: ApiPrivilegesByRole = {
+ anon: ['SELECT'],
+ authenticated: ['SELECT'],
+ service_role: ['SELECT'],
+ }
+ expect(isFullyGranted(privileges)).toBe(false)
+ })
+
+ it('returns false when no role has any privileges', () => {
+ const privileges: ApiPrivilegesByRole = {
+ anon: [],
+ authenticated: [],
+ service_role: [],
+ }
+ expect(isFullyGranted(privileges)).toBe(false)
+ })
+
+ it('tolerates duplicate privilege entries', () => {
+ const privileges: ApiPrivilegesByRole = {
+ anon: ['SELECT', 'SELECT', 'INSERT', 'UPDATE', 'DELETE'],
+ authenticated: ['SELECT', 'INSERT', 'UPDATE', 'DELETE'],
+ service_role: ['SELECT', 'INSERT', 'UPDATE', 'DELETE'],
+ }
+ expect(isFullyGranted(privileges)).toBe(true)
+ })
+
+ it('ignores privilege order', () => {
+ const privileges: ApiPrivilegesByRole = {
+ anon: ['DELETE', 'UPDATE', 'INSERT', 'SELECT'],
+ authenticated: ['UPDATE', 'DELETE', 'SELECT', 'INSERT'],
+ service_role: ['INSERT', 'SELECT', 'DELETE', 'UPDATE'],
+ }
+ expect(isFullyGranted(privileges)).toBe(true)
+ })
+})
diff --git a/apps/studio/data/privileges/table-api-access-query.ts b/apps/studio/data/privileges/table-api-access-query.ts
index 3a18e128a51..43e289f68b9 100644
--- a/apps/studio/data/privileges/table-api-access-query.ts
+++ b/apps/studio/data/privileges/table-api-access-query.ts
@@ -7,7 +7,13 @@ import {
} from './table-privileges-query'
import type { ConnectionVars } from '@/data/common.types'
import { useIsSchemaExposed } from '@/hooks/misc/useIsSchemaExposed'
-import { isApiAccessRole, isApiPrivilegeType, type ApiPrivilegesByRole } from '@/lib/data-api-types'
+import {
+ API_ACCESS_ROLES,
+ API_PRIVILEGE_TYPES,
+ isApiAccessRole,
+ isApiPrivilegeType,
+ type ApiPrivilegesByRole,
+} from '@/lib/data-api-types'
import type { Prettify } from '@/lib/type-helpers'
import type { UseCustomQueryOptions } from '@/types'
@@ -63,15 +69,35 @@ export type UseTableApiAccessQueryParams = Prettify<
export type DataApiAccessType = 'none' | 'exposed-schema-no-grants' | 'access'
+/**
+ * Mirrors the "granted | custom | revoked" classification used by the Data API
+ * settings page (see getTableGrantsCTEs in packages/pg-meta privileges.ts).
+ * - `granted`: all 3 API roles (anon/authenticated/service_role) have all 4
+ * CRUD privileges — the standard Data API exposure.
+ * - `custom`: at least one grant exists but it's not the full standard set.
+ * - `revoked`: no API role has any privilege (mapped to `exposed-schema-no-grants`).
+ */
+export type TableGrantStatus = 'granted' | 'custom'
+
export type TableApiAccessData =
| {
apiAccessType: 'access'
+ grantStatus: TableGrantStatus
privileges: ApiPrivilegesByRole
}
| {
apiAccessType: 'none' | 'exposed-schema-no-grants'
}
+/**
+ * Matches the "granted" branch of getTableGrantsCTEs in packages/pg-meta's
+ * privileges.ts — all 3 API roles must have all 4 CRUD privileges.
+ */
+export const isFullyGranted = (privileges: ApiPrivilegesByRole): boolean =>
+ API_ACCESS_ROLES.every((role) =>
+ API_PRIVILEGE_TYPES.every((priv) => privileges[role].includes(priv))
+ )
+
export type TableApiAccessMap = Prettify<Record<string, TableApiAccessData>>
export type UseTableApiAccessQueryReturn =
@@ -189,6 +215,7 @@ export const useTableApiAccessQuery = (
resultData[tableName] = hasApiPrivileges
? {
apiAccessType: 'access',
+ grantStatus: isFullyGranted(tablePrivileges) ? 'granted' : 'custom',
privileges: tablePrivileges,
}
: { apiAccessType: 'exposed-schema-no-grants' }
diff --git a/apps/studio/data/tables/keys.ts b/apps/studio/data/tables/keys.ts
index da37b9757b1..9d842f69d31 100644
--- a/apps/studio/data/tables/keys.ts
+++ b/apps/studio/data/tables/keys.ts
@@ -4,10 +4,4 @@ export const tableKeys = {
['projects', projectRef, 'tables', schema, includeColumns].filter(Boolean),
retrieve: (projectRef: string | undefined, name: string, schema: string) =>
['projects', projectRef, 'table', schema, name].filter(Boolean),
- rolesAccess: (projectRef: string | undefined, schema: string) => [
- 'projects',
- projectRef,
- 'roles-access',
- { schema },
- ],
}
diff --git a/apps/studio/data/tables/tables-roles-access-query.ts b/apps/studio/data/tables/tables-roles-access-query.ts
deleted file mode 100644
index 99b393e3b15..00000000000
--- a/apps/studio/data/tables/tables-roles-access-query.ts
+++ /dev/null
@@ -1,49 +0,0 @@
-import { getTablesWithAnonAuthenticatedAccessSQL } from '@supabase/pg-meta'
-import { useQuery } from '@tanstack/react-query'
-
-import { tableKeys } from './keys'
-import { executeSql, ExecuteSqlError } from '@/data/sql/execute-sql-query'
-import { UseCustomQueryOptions } from '@/types'
-
-type TablesRolesAccessArgs = {
- schema: string
-}
-
-export type TablesRolesAccessVariables = TablesRolesAccessArgs & {
- projectRef?: string
- connectionString?: string | null
-}
-
-export async function getTablesWithAnonAuthenticatedAccess(
- { schema, projectRef, connectionString }: TablesRolesAccessVariables,
- signal?: AbortSignal
-) {
- if (!schema) throw new Error('schema is required')
-
- const sql = getTablesWithAnonAuthenticatedAccessSQL({ schema })
-
- const { result } = (await executeSql(
- { projectRef, connectionString, sql, queryKey: ['TablesRolesAccess', schema] },
- signal
- )) as { result: { table_name: string }[] }
-
- return new Set(result.map((r) => r.table_name))
-}
-
-export type TablesRolesAccessData = Awaited<ReturnType<typeof getTablesWithAnonAuthenticatedAccess>>
-export type TablesRolesAccessError = ExecuteSqlError
-
-export const useTablesRolesAccessQuery = <TData = TablesRolesAccessData>(
- { projectRef, connectionString, schema }: TablesRolesAccessVariables,
- {
- enabled = true,
- ...options
- }: UseCustomQueryOptions<TablesRolesAccessData, TablesRolesAccessError, TData> = {}
-) =>
- useQuery<TablesRolesAccessData, TablesRolesAccessError, TData>({
- queryKey: tableKeys.rolesAccess(projectRef, schema),
- queryFn: ({ signal }) =>
- getTablesWithAnonAuthenticatedAccess({ projectRef, connectionString, schema }, signal),
- enabled: enabled && typeof projectRef !== 'undefined' && typeof schema !== 'undefined',
- ...options,
- })