Skip to content

Commit ce3a67d

Browse files
authored
Fix data api exposed schemas to handle spaces in schema names (supabase#42645)
## Context Fixes Data API settings, exposed schemas parameter to handle schemas with spaces in the name - was buggy due to the global removal of all spaces in the `db_schema` string (presumably old logic as the input field used to a free input in the past, which now is a multi select) Also adjusts the admonition when the public schema is not exposed Before: <img width="1104" height="289" alt="image" src="https://github.com/user-attachments/assets/10611e82-70ac-427b-b369-f1df923d3862" /> After: <img width="1095" height="268" alt="image" src="https://github.com/user-attachments/assets/425ee6c8-44e7-45ec-8199-22ebd8e4225d" /> ## To test - [ ] Have a schema with a space in it's name - [ ] Verify that you can add + save , remove + save that schema in the data api settings exposed schemas field with no issues
1 parent 6fe4d0c commit ce3a67d

1 file changed

Lines changed: 42 additions & 43 deletions

File tree

apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
import { zodResolver } from '@hookform/resolvers/zod'
22
import { PermissionAction } from '@supabase/shared-types/out/constants'
3-
import { indexOf } from 'lodash'
4-
import { Lock } from 'lucide-react'
5-
import Link from 'next/link'
6-
import { useEffect, useState } from 'react'
7-
import { useForm } from 'react-hook-form'
8-
import { toast } from 'sonner'
9-
import { z } from 'zod'
10-
113
import { useParams } from 'common'
124
import { DocsButton } from 'components/ui/DocsButton'
135
import { FormActions } from 'components/ui/Forms/FormActions'
@@ -18,21 +10,27 @@ import { useSchemasQuery } from 'data/database/schemas-query'
1810
import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
1911
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
2012
import { DOCS_URL } from 'lib/constants'
13+
import { indexOf } from 'lodash'
14+
import { Lock } from 'lucide-react'
15+
import Link from 'next/link'
16+
import { useEffect, useState } from 'react'
17+
import { useForm } from 'react-hook-form'
18+
import { toast } from 'sonner'
2119
import {
20+
Alert_Shadcn_,
2221
AlertDescription_Shadcn_,
2322
AlertTitle_Shadcn_,
24-
Alert_Shadcn_,
2523
Button,
2624
Card,
2725
CardContent,
2826
CardFooter,
2927
CardHeader,
30-
CollapsibleContent_Shadcn_,
3128
Collapsible_Shadcn_,
29+
CollapsibleContent_Shadcn_,
30+
Form_Shadcn_,
3231
FormControl_Shadcn_,
3332
FormField_Shadcn_,
3433
FormItem_Shadcn_,
35-
Form_Shadcn_,
3634
Input_Shadcn_,
3735
PrePostTab,
3836
Skeleton,
@@ -49,6 +47,8 @@ import {
4947
MultiSelectorList,
5048
MultiSelectorTrigger,
5149
} from 'ui-patterns/multi-select'
50+
import { z } from 'zod'
51+
5252
import { HardenAPIModal } from './HardenAPIModal'
5353

5454
const formSchema = z
@@ -128,7 +128,7 @@ export const PostgrestConfig = () => {
128128
const isGraphqlExtensionEnabled =
129129
(extensions ?? []).find((ext) => ext.name === 'pg_graphql')?.installed_version !== null
130130

131-
const dbSchema = config?.db_schema ? config?.db_schema.replace(/ /g, '').split(',') : []
131+
const dbSchema = config?.db_schema ? config?.db_schema.split(',').map((x) => x.trim()) : []
132132
const defaultValues = {
133133
dbSchema,
134134
maxRows: config?.max_rows,
@@ -311,38 +311,37 @@ export const PostgrestConfig = () => {
311311
</MultiSelectorContent>
312312
</MultiSelector>
313313
)}
314-
315-
{!field.value.includes('public') && field.value.length > 0 && (
316-
<Admonition
317-
type="default"
318-
title="The public schema for this project is not exposed"
319-
className="mt-2"
320-
description={
321-
<>
322-
<p className="prose text-sm">
323-
You will not be able to query tables and views in the{' '}
324-
<code className="text-code-inline">public</code> schema via
325-
supabase-js or HTTP clients.
326-
</p>
327-
{isGraphqlExtensionEnabled && (
328-
<>
329-
<p className="prose text-sm mt-2">
330-
Tables in the{' '}
331-
<code className="text-code-inline">public</code> schema
332-
are still exposed over our GraphQL endpoints.
333-
</p>
334-
<Button asChild type="default" className="mt-2">
335-
<Link href={`/project/${projectRef}/database/extensions`}>
336-
Disable the pg_graphql extension
337-
</Link>
338-
</Button>
339-
</>
340-
)}
341-
</>
342-
}
343-
/>
344-
)}
345314
</FormItemLayout>
315+
{!field.value.includes('public') && field.value.length > 0 && (
316+
<Admonition
317+
type="default"
318+
title="The public schema for this project is not exposed"
319+
className="mt-2"
320+
description={
321+
<>
322+
<p className="text-sm">
323+
You will not be able to query tables and views in the{' '}
324+
<code className="text-code-inline">public</code> schema via
325+
supabase-js or HTTP clients.
326+
</p>
327+
{isGraphqlExtensionEnabled && (
328+
<>
329+
<p className="text-sm">
330+
Tables in the{' '}
331+
<code className="text-code-inline">public</code> schema are
332+
still exposed over our GraphQL endpoints.
333+
</p>
334+
<Button asChild type="default" className="mt-2">
335+
<Link href={`/project/${projectRef}/database/extensions`}>
336+
Disable the pg_graphql extension
337+
</Link>
338+
</Button>
339+
</>
340+
)}
341+
</>
342+
}
343+
/>
344+
)}
346345
</FormItem_Shadcn_>
347346
)}
348347
/>

0 commit comments

Comments
 (0)