Files
supabase/apps/studio/components/interfaces/Database/ProtectedSchemaWarning.tsx
Ivan Vasilov b3c6992e56 feat: Make the protected schemas dynamic, namespace schemas are now protected (#37290)
* Add hooks for async protected schemas.

* Migrate the ProtectedSchemaWarning to support the new implementation.

* sq

* Migrate all uses of protected schemas to the new approach.

* Delete extra file.

* Refactor the import foreign schema dialog to forbid protected and exposed schemas.

* Add the type to the protected schema.

* Revert ImportForeignSchemaDialog, it'll be addressed in another PR.

* Update apps/studio/hooks/useProtectedSchemas.ts

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>

* Fix a bad commit.

* Minor fixes.

* Fix the FDW delete mutation to handle names with numbers.

* Simplify the logic to skip a fetch.

* Minor fixes.

* Make the useIcebergFdwSchemasQuery work for all iceberg FDWs.

* Fix the tab schemas to always show in the Table Editor.

* Apply suggestion from @joshenlim

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>

* Fix a minor typo.

* Refactor ProtectedSchemaWarning to use Admonition, and standardise input field for target schema iceberg

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-07-30 11:38:50 +02:00

110 lines
3.2 KiB
TypeScript

import { useState } from 'react'
import {
Button,
Dialog,
DialogContent,
DialogFooter,
DialogHeader,
DialogSection,
DialogSectionSeparator,
DialogTitle,
DialogTrigger,
cn,
} from 'ui'
import { INTERNAL_SCHEMAS, useIsProtectedSchema } from 'hooks/useProtectedSchemas'
import { Admonition } from 'ui-patterns'
export const ProtectedSchemaDialog = ({ onClose }: { onClose: () => void }) => {
return (
<>
<DialogHeader>
<DialogTitle>Schemas managed by Supabase</DialogTitle>
</DialogHeader>
<DialogSectionSeparator />
<DialogSection className="space-y-2 prose">
<p className="text-sm">
The following schemas are managed by Supabase and are currently protected from write
access through the dashboard.
</p>
<div className="flex flex-wrap gap-1">
{INTERNAL_SCHEMAS.map((schema) => (
<code key={schema} className="text-xs">
{schema}
</code>
))}
</div>
<p className="text-sm !mt-4">
These schemas are critical to the functionality of your Supabase project and hence we
highly recommend not altering them.
</p>
<p className="text-sm">
You can, however, still interact with those schemas through the SQL Editor although we
advise you only do so if you know what you are doing.
</p>
</DialogSection>
<DialogFooter>
<div className="flex items-center justify-end space-x-2">
<Button type="default" onClick={onClose}>
Understood
</Button>
</div>
</DialogFooter>
</>
)
}
export const ProtectedSchemaWarning = ({
size = 'md',
schema,
entity,
}: {
size?: 'sm' | 'md'
schema: string
entity: string
}) => {
const [showModal, setShowModal] = useState(false)
const { isSchemaLocked, reason } = useIsProtectedSchema({ schema })
if (!isSchemaLocked) return null
return (
<Admonition
showIcon={false}
type="note"
title={
size === 'sm' ? `Viewing protected schema` : `Viewing ${entity} from a protected schema`
}
className={cn(
'[&>div>p]:prose [&>div>p]:max-w-full [&>div>p]:!leading-normal',
size === 'sm' ? '[&>div>p]:text-xs' : '[&>div>p]:text-sm'
)}
>
{reason === 'fdw' ? (
<p>
The <code className="text-xs">{schema}</code> schema is used by Supabase to connect to
analytics buckets and is read-only through the dashboard.
</p>
) : (
<>
<p className="mb-2">
The <code className="text-xs">{schema}</code> schema is managed by Supabase and is
read-only through the dashboard.
</p>
<Dialog open={showModal} onOpenChange={setShowModal}>
<DialogTrigger asChild>
<Button type="default" size="tiny" onClick={() => setShowModal(true)}>
Learn more
</Button>
</DialogTrigger>
<DialogContent>
<ProtectedSchemaDialog onClose={() => setShowModal(false)} />
</DialogContent>
</Dialog>
</>
)}
</Admonition>
)
}