Skip to content

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

Disable 'New table' button in schema visualizer page if schema is pro… (#40983)

Marouane Souda0ee0bf6968bf
diff --git a/apps/studio/components/interfaces/Database/Schemas/SchemaGraph.tsx b/apps/studio/components/interfaces/Database/Schemas/SchemaGraph.tsx
index 3b2035ce4ec..0f14d8a8485 100644
--- a/apps/studio/components/interfaces/Database/Schemas/SchemaGraph.tsx
+++ b/apps/studio/components/interfaces/Database/Schemas/SchemaGraph.tsx
@@ -9,6 +9,7 @@ import 'reactflow/dist/style.css'
import { toast } from 'sonner'
import { Button } from 'ui'
import { Admonition } from 'ui-patterns/admonition'
+import { PermissionAction } from '@supabase/shared-types/out/constants'
import { LOCAL_STORAGE_KEYS, useParams } from 'common'
import AlertError from 'components/ui/AlertError'
@@ -18,7 +19,9 @@ import { useSchemasQuery } from 'data/database/schemas-query'
import { useTablesQuery } from 'data/tables/tables-query'
import { useLocalStorage } from 'hooks/misc/useLocalStorage'
import { useQuerySchemaState } from 'hooks/misc/useSchemaQueryState'
+import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
+import { useIsProtectedSchema } from 'hooks/useProtectedSchemas'
import { tablesToSQL } from 'lib/helpers'
import {
copyToClipboard,
@@ -90,6 +93,15 @@ export const SchemaGraph = () => {
{}
)
+ const { can: canUpdateTables } = useAsyncCheckPermissions(
+ PermissionAction.TENANT_SQL_ADMIN_WRITE,
+ 'tables'
+ )
+
+ const { isSchemaLocked } = useIsProtectedSchema({ schema: selectedSchema })
+
+ const canAddTables = canUpdateTables && !isSchemaLocked
+
const resetLayout = () => {
const nodes = reactFlowInstance.getNodes()
const edges = reactFlowInstance.getEdges()
@@ -288,11 +300,20 @@ export const SchemaGraph = () => {
type="default"
className="max-w-md"
title="No tables in schema"
- description={`The “${selectedSchema}” schema doesn’t have any tables.`}
+ description={
+ isSchemaLocked
+ ? `The “${selectedSchema}” schema is managed by Supabase and is read-only through
+ the dashboard.`
+ : !canUpdateTables
+ ? 'You need additional permissions to create tables'
+ : `The “${selectedSchema}” schema doesn’t have any tables.`
+ }
>
- <Button asChild className="mt-2" type="default" icon={<Plus />}>
- <Link href={`/project/${ref}/editor?create=table`}>New table</Link>
- </Button>
+ {canAddTables && (
+ <Button asChild className="mt-2" type="default" icon={<Plus />}>
+ <Link href={`/project/${ref}/editor?create=table`}>New table</Link>
+ </Button>
+ )}
</Admonition>
</div>
) : (