The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Revert "Chore/allow disabling public schema" (#22728)
Alaister Young8519f2dcc4fd
diff --git a/apps/studio/components/interfaces/Docs/Introduction.tsx b/apps/studio/components/interfaces/Docs/Introduction.tsxindex 6c4c68c167e..579e13dec51 100644--- a/apps/studio/components/interfaces/Docs/Introduction.tsx+++ b/apps/studio/components/interfaces/Docs/Introduction.tsx@@ -1,10 +1,6 @@-import { useParams } from 'common'-import Snippets from 'components/interfaces/Docs/Snippets'import type { AutoApiService } from 'data/config/project-api-query'-import { useProjectPostgrestConfigQuery } from 'data/config/project-postgrest-config-query'-+import Snippets from 'components/interfaces/Docs/Snippets'import CodeSnippet from './CodeSnippet'-import PublicSchemaNotEnabledAlert from './PublicSchemaNotEnabledAlert'interface Props {autoApiService: AutoApiService@@ -12,22 +8,16 @@ interface Props {}export default function Introduction({ autoApiService, selectedLang }: Props) {- const { ref: projectRef } = useParams()-- const { data: config } = useProjectPostgrestConfigQuery({ projectRef })-- const isPublicSchemaEnabled = config?.db_schema- .split(',')- .map((name) => name.trim())- .includes('public')-return (- <div className="doc-section doc-section--client-libraries">- <article className="code">- <CodeSnippet selectedLang={selectedLang} snippet={Snippets.init(autoApiService.endpoint)} />-- {!isPublicSchemaEnabled && <PublicSchemaNotEnabledAlert />}- </article>- </div>+ <>+ <div className="doc-section doc-section--client-libraries">+ <article className="code">+ <CodeSnippet+ selectedLang={selectedLang}+ snippet={Snippets.init(autoApiService.endpoint)}+ />+ </article>+ </div>+ </>)}diff --git a/apps/studio/components/interfaces/Docs/Pages/Tables/Introduction.tsx b/apps/studio/components/interfaces/Docs/Pages/Tables/Introduction.tsxindex d3116933cb6..499b9709810 100644--- a/apps/studio/components/interfaces/Docs/Pages/Tables/Introduction.tsx+++ b/apps/studio/components/interfaces/Docs/Pages/Tables/Introduction.tsx@@ -3,22 +3,13 @@ import Link from 'next/link'import CodeSnippet from 'components/interfaces/Docs/CodeSnippet'import GeneratingTypes from 'components/interfaces/Docs/GeneratingTypes'-import { useProjectPostgrestConfigQuery } from 'data/config/project-postgrest-config-query'-import PublicSchemaNotEnabledAlert from '../../PublicSchemaNotEnabledAlert'interface IntroductionProps {selectedLang: 'bash' | 'js'}const Introduction = ({ selectedLang }: IntroductionProps) => {- const { ref: projectRef } = useParams()-- const { data: config } = useProjectPostgrestConfigQuery({ projectRef })-- const isPublicSchemaEnabled = config?.db_schema- .split(',')- .map((name) => name.trim())- .includes('public')+ const { ref } = useParams()return (<>@@ -29,8 +20,6 @@ const Introduction = ({ selectedLang }: IntroductionProps) => {All views and tables in the <code>public</code> schema and accessible by the activedatabase role for a request are available for querying.</p>-- {!isPublicSchemaEnabled && <PublicSchemaNotEnabledAlert />}</article></div>@@ -67,7 +56,7 @@ const Introduction = ({ selectedLang }: IntroductionProps) => {If you still want to use GraphQL, you can. Supabase provides you with a full Postgresdatabase, so as long as your middleware can connect to the database then you can stilluse the tools you love. You can find the database connection details{' '}- <Link href={`/project/${projectRef}/settings/database`}>in the settings.</Link>+ <Link href={`/project/${ref}/settings/database`}>in the settings.</Link></p></article><article className="code">diff --git a/apps/studio/components/interfaces/Docs/PublicSchemaNotEnabledAlert.tsx b/apps/studio/components/interfaces/Docs/PublicSchemaNotEnabledAlert.tsxdeleted file mode 100644index 99be76b020f..00000000000--- a/apps/studio/components/interfaces/Docs/PublicSchemaNotEnabledAlert.tsx+++ /dev/null@@ -1,37 +0,0 @@-import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, Button } from 'ui'-import { Info } from 'lucide-react'-import ReactMarkdown from 'react-markdown'-import Link from 'next/link'-import { useParams } from 'common'--const PublicSchemaNotEnabledAlert = () => {- const { ref: projectRef } = useParams()-- return (- <Alert_Shadcn_ variant="default">- <Info className="h-4 w-4" />- <AlertTitle_Shadcn_ className="!-mt-4">- <ReactMarkdown>The `public` schema for this project is not exposed</ReactMarkdown>- </AlertTitle_Shadcn_>- <AlertDescription_Shadcn_ className="grid gap-3 !-mt-7">- <ReactMarkdown>- You will not be able to query tables and views in the `public` schema via supabase-js or- HTTP clients.- </ReactMarkdown>-- <div className="!-mt-4 inline-block">- <Button asChild type="default">- <Link- href={`/project/${projectRef}/settings/api#postgrest-config`}- className="!no-underline !hover:bg-surface-100 !text-foreground"- >- View schema settings- </Link>- </Button>- </div>- </AlertDescription_Shadcn_>- </Alert_Shadcn_>- )-}--export default PublicSchemaNotEnabledAlertdiff --git a/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx b/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsxindex c865116a3c4..6d2110204b1 100644--- a/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx+++ b/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx@@ -16,50 +16,29 @@ import { useProjectPostgrestConfigQuery } from 'data/config/project-postgrest-coimport { useProjectPostgrestConfigUpdateMutation } from 'data/config/project-postgrest-config-update-mutation'import { useSchemasQuery } from 'data/database/schemas-query'import { useCheckPermissions } from 'hooks'-import { AlertCircle, Info } from 'lucide-react'-import {- AlertDescription_Shadcn_,- AlertTitle_Shadcn_,- Alert_Shadcn_,- Button,- Form,- Input,- InputNumber,-} from 'ui'-import { MultiSelectV2 } from 'ui-patterns/MultiSelect/MultiSelectV2'-import ShimmeringLoader from 'ui-patterns/ShimmeringLoader'--import { useDatabaseExtensionsQuery } from 'data/database-extensions/database-extensions-query'-import Link from 'next/link'+import { Form, IconAlertCircle, Input, InputNumber } from 'ui'+import MultiSelect from 'ui-patterns/MultiSelect'const PostgrestConfig = () => {const { ref: projectRef } = useParams()const { project } = useProjectContext()-- const { data: schemas, isLoading: isLoadingSchemas } = useSchemasQuery({+ const { data: schemas } = useSchemasQuery({projectRef: project?.ref,connectionString: project?.connectionString,})const { data: config, isError } = useProjectPostgrestConfigQuery({ projectRef })-const { mutate: updatePostgrestConfig, isLoading: isUpdating } =useProjectPostgrestConfigUpdateMutation({onSuccess: () => {toast.success('Successfully saved settings')},})-const canUpdatePostgrestConfig = useCheckPermissions(PermissionAction.UPDATE,'custom_config_postgrest')- const { data: extensions } = useDatabaseExtensionsQuery({- projectRef: project?.ref,- connectionString: project?.connectionString,- })-const formId = 'project-postgres-config'const initialValues = { db_schema: '', max_rows: '', db_extra_search_path: '' }@@ -73,6 +52,7 @@ const PostgrestConfig = () => {})}+ const permanentSchema = ['public', 'storage']const hiddenSchema = ['auth', 'pgbouncer', 'hooks', 'extensions']const schema =schemas@@ -85,22 +65,15 @@ const PostgrestConfig = () => {id: x.id,value: x.name,name: x.name,- disabled: false,+ disabled: indexOf(permanentSchema, x.name) >= 0 ? true : false,}}) ?? []- const isPublicSchemaEnabled = config?.db_schema- .split(',')- .map((name) => name.trim())- .includes('public')-- const isGraphqlExtensionEnabled =- (extensions ?? []).find((ext) => ext.name === 'pg_graphql')?.installed_version !== null-return (<Form id={formId} initialValues={initialValues} validate={() => {}} onSubmit={updateConfig}>{({ handleReset, resetForm, values, initialValues }: any) => {const hasChanges = JSON.stringify(values) !== JSON.stringify(initialValues)+// [Alaister] although this "technically" is breaking the rules of React hooks// it won't error because the hooks are always rendered in the same order// eslint-disable-next-line react-hooks/rules-of-hooks@@ -111,7 +84,6 @@ const PostgrestConfig = () => {max_rows: config.max_rows,db_extra_search_path: config.db_extra_search_path ?? '',}-resetForm({ values, initialValues: values })}}, [config])@@ -140,81 +112,51 @@ const PostgrestConfig = () => {>{isError ? (<div className="flex items-center justify-center py-8 space-x-2">- <AlertCircle size={16} strokeWidth={1.5} />+ <IconAlertCircle size={16} strokeWidth={1.5} /><p className="text-sm text-foreground-light">Failed to retrieve API settings</p></div>) : (<><FormSection header={<FormSectionLabel>Exposed schemas</FormSectionLabel>}>- {isLoadingSchemas ? (- <div className="col-span-12 flex flex-col gap-2 lg:col-span-7">- <ShimmeringLoader />- <ShimmeringLoader className="w-3/4" />- </div>- ) : (- <FormSectionContent loading={false}>- {schema.length >= 1 && (- <div className="grid gap-2">- <MultiSelectV2- options={schema}- disabled={!canUpdatePostgrestConfig}- value={- values?.db_schema- ? values.db_schema.replace(/ /g, '').split(',')- : []- }- placeholder="Choose a schema to expose"- searchPlaceholder="Search for a schema"- onChange={(event) => {- let updatedValues: any = values- updatedValues.db_schema = event.join(', ')- resetForm({ values: updatedValues, initialValues: updatedValues })- updateConfig({ ...updatedValues })- }}- />- <p className="text-foreground-lighter text-sm">+ <FormSectionContent loading={false}>+ {schema.length >= 1 && (+ <MultiSelect+ disabled={!canUpdatePostgrestConfig}+ options={schema}+ descriptionText={+ <>The schemas to expose in your API. Tables, views and stored proceduresin these schemas will get API endpoints.- </p>-- {!isPublicSchemaEnabled && (- <Alert_Shadcn_ variant="default">- <Info className="h-4 w-4" />- <AlertTitle_Shadcn_>- The public schema for this project is not exposed- </AlertTitle_Shadcn_>- <AlertDescription_Shadcn_>- <p>- You will not be able to query tables and views in the{' '}- <code>public</code> schema via supabase-js or HTTP clients.- </p>- {isGraphqlExtensionEnabled && (- <div className="grid gap-3 mt-2">- <div>- Tables in the <code>public</code> schema are still exposed- over our GraphQL endpoints.- </div>- <p>- <Button asChild type="default">- <Link- href={`/project/${projectRef}/database/extensions`}- className="!no-underline !hover:bg-surface-100 !text-foreground"- >- Disable the pg_graphql extension- </Link>- </Button>- </p>- </div>- )}- </AlertDescription_Shadcn_>- </Alert_Shadcn_>- )}- </div>- )}- </FormSectionContent>- )}+ <code className="text-xs">public</code> and{' '}+ <code className="text-xs">storage</code> are protected by default.+ </>+ }+ emptyMessage={+ <>+ <IconAlertCircle strokeWidth={2} />+ <div className="flex flex-col mt-2 text-center">+ <p className="text-sm align-center">+ No schema available to choose+ </p>+ <p className="text-xs opacity-50">+ New schemas you create will appear here+ </p>+ </div>+ </>+ }+ // value must be passed as array of strings+ value={(values?.db_schema ?? '').replace(/ /g, '').split(',')}+ // onChange returns array of strings+ onChange={(event) => {+ let updatedValues: any = values+ updatedValues.db_schema = event.join(', ')+ resetForm({ values: updatedValues, initialValues: updatedValues })+ updateConfig({ ...updatedValues })+ }}+ />+ )}+ </FormSectionContent></FormSection>-<FormSection header={<FormSectionLabel>Extra search path</FormSectionLabel>}><FormSectionContent loading={false}><Inputdiff --git a/apps/studio/components/interfaces/Settings/API/ServiceList.tsx b/apps/studio/components/interfaces/Settings/API/ServiceList.tsxindex 328dcfbaa86..6a15bfa2ab3 100644--- a/apps/studio/components/interfaces/Settings/API/ServiceList.tsx+++ b/apps/studio/components/interfaces/Settings/API/ServiceList.tsx@@ -169,7 +169,7 @@ const ServiceList = () => {<JWTSettings /></section>- <section id="postgrest-config">+ <section><PostgrestConfig /></section></>