Skip to content

Commit 0283d92

Browse files
authored
fix: allow users to remove missing schemas from the data API (supabase#46169)
## Problem Exposed schemas (from the Data API) that have been deleted manually (for instance, using the SQL editor) are still present in the Data API setting, crashing Postgrest clients. However, the Data API setting does not show them anymore preventing users from fixing the issue. ## Solution - Detect missing schemas and show users an error message - Make missing schema visually distinct - Allow users to unselect them and update the Data API settings ## How to test - Create a new schema - Verify that it is exposed (expose it if necessary) in the Data API settings - Delete the schema using the SQL editor - Verify that you can unselect it from the Data API settings ## Screenshots <img width="470" height="243" alt="image" src="https://github.com/user-attachments/assets/2a1f7dc5-c9a9-4779-9f26-1d3e0f66fb8f" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Dropdown for exposed API schemas now shows selected schemas that no longer exist and labels them "This schema does not exist", allowing users to toggle them. * "Exposed schemas" field now shows an inline validation/error message when selected schemas are unavailable to help resolve configuration issues. <!-- review_stack_entry_start --> [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/46169?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent c8e1eb1 commit 0283d92

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ export const ExposedSchemaSelector = ({
5757
[allSchemas]
5858
)
5959

60+
const missingExposedSchema = useMemo(
61+
() => selectedSchemas.filter((schema) => !schemas.some((s) => s.name === schema)),
62+
[schemas, selectedSchemas]
63+
)
64+
6065
const selectedSet = useMemo(() => new Set(selectedSchemas), [selectedSchemas])
6166
const selectedCount = schemas.filter((s) => selectedSet.has(s.name)).length
6267

@@ -110,6 +115,26 @@ export const ExposedSchemaSelector = ({
110115
</p>
111116
</CommandEmpty>
112117
<ScrollArea className={schemas.length > 7 ? 'h-[210px]' : ''}>
118+
{missingExposedSchema.map((schema) => (
119+
<CommandItem
120+
key={schema}
121+
value={schema}
122+
className="cursor-pointer w-full"
123+
onSelect={() => {
124+
onToggleSchema(schema)
125+
}}
126+
>
127+
<div className="w-full flex flex-col">
128+
<div className="w-full flex items-center gap-x-2">
129+
<Check size={16} className="text-brand shrink-0" />
130+
<span className="truncate">{schema}</span>
131+
</div>
132+
<span className="pl-6 text-destructive text-[11px]">
133+
This schema does not exist
134+
</span>
135+
</div>
136+
</CommandItem>
137+
))}
113138
{schemas.map((schema) => {
114139
const isExposed = selectedSet.has(schema.name)
115140

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,11 @@ export const PostgrestConfig = () => {
260260
name: 'functionNamesToRemove',
261261
})
262262

263+
const missingExposedSchema = useMemo(
264+
() => watchedDbSchema.filter((schema) => !allSchemas.some((s) => s.name === schema)),
265+
[allSchemas, watchedDbSchema]
266+
)
267+
263268
return (
264269
<PageSection id="postgrest-config" className="first:pt-0">
265270
<PageSectionContent>
@@ -282,6 +287,9 @@ export const PostgrestConfig = () => {
282287
layout="flex-row-reverse"
283288
label="Exposed schemas"
284289
description="Select schemas to include in the Data API. Schemas must be included before tables can be exposed."
290+
error={
291+
missingExposedSchema.length > 0 ? 'Some exposed schemas are missing' : null
292+
}
285293
>
286294
<ExposedSchemaSelector
287295
selectedSchemas={watchedDbSchema}

0 commit comments

Comments
 (0)