The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix: Small fixes in Analytics and Vector Buckets (#40386)
Ivan Vasilov1032d139302e
diff --git a/apps/studio/components/interfaces/Database/ProtectedSchemaWarning.tsx b/apps/studio/components/interfaces/Database/ProtectedSchemaWarning.tsxindex f502a092127..5ba9d30c22f 100644--- a/apps/studio/components/interfaces/Database/ProtectedSchemaWarning.tsx+++ b/apps/studio/components/interfaces/Database/ProtectedSchemaWarning.tsx@@ -65,7 +65,7 @@ export const ProtectedSchemaWarning = ({entity: string}) => {const [showModal, setShowModal] = useState(false)- const { isSchemaLocked, reason } = useIsProtectedSchema({ schema })+ const { isSchemaLocked, reason, fdwType } = useIsProtectedSchema({ schema })if (!isSchemaLocked) return null@@ -81,11 +81,16 @@ export const ProtectedSchemaWarning = ({size === 'sm' ? '[&>div>p]:text-xs' : '[&>div>p]:text-sm')}>- {reason === 'fdw' ? (+ {reason === 'fdw' && fdwType === 'iceberg' ? (<p>The <code className="text-xs">{schema}</code> schema is used by Supabase to connect toanalytics buckets and is read-only through the dashboard.</p>+ ) : reason === 'fdw' && fdwType === 's3_vectors' ? (+ <p>+ The <code className="text-xs">{schema}</code> schema is used by Supabase to connect to+ vector buckets and is read-only through the dashboard.+ </p>) : (<><p className="mb-2">diff --git a/apps/studio/components/interfaces/Integrations/Wrappers/Wrappers.constants.ts b/apps/studio/components/interfaces/Integrations/Wrappers/Wrappers.constants.tsindex 113d6df59f5..be65614c608 100644--- a/apps/studio/components/interfaces/Integrations/Wrappers/Wrappers.constants.ts+++ b/apps/studio/components/interfaces/Integrations/Wrappers/Wrappers.constants.ts@@ -27,7 +27,7 @@ export const WRAPPER_HANDLERS = {ORB: 'wasm_fdw_handler',}-const SUPABASE_TARGET_SCHEMA_OPTION: ServerOption = {+export const SUPABASE_TARGET_SCHEMA_OPTION: ServerOption = {name: 'supabase_target_schema',label: 'Target Schema',required: false,@@ -1458,6 +1458,7 @@ export const WRAPPERS: WrapperMeta[] = [secureEntry: false,defaultValue: '',},+ SUPABASE_TARGET_SCHEMA_OPTION,],},canTargetSchema: true,diff --git a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/index.tsx b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/index.tsxindex 57d39833d50..16d0712664c 100644--- a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/index.tsx+++ b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/index.tsx@@ -1,3 +1,7 @@+import Link from 'next/link'+import { useRouter } from 'next/navigation'+import { useState } from 'react'+import { useParams } from 'common'import { ScaffoldHeader, ScaffoldSection, ScaffoldSectionTitle } from 'components/layouts/Scaffold'import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'@@ -5,9 +9,6 @@ import { useAnalyticsBucketsQuery } from 'data/storage/analytics-buckets-query'import { Bucket as BucketIcon } from 'icons'import { BASE_PATH } from 'lib/constants'import { ChevronRight, ExternalLink, Search } from 'lucide-react'-import Link from 'next/link'-import { useRouter } from 'next/navigation'-import { useState } from 'react'import {Badge,Button,@@ -48,7 +49,7 @@ export const AnalyticsBuckets = () => {) => {const url = `/project/${ref}/storage/analytics/buckets/${encodeURIComponent(bucketId)}`if (event.metaKey || event.ctrlKey) {- window.open(url, '_blank')+ window.open(`${BASE_PATH}${url}`, '_blank')} else {router.push(url)}diff --git a/apps/studio/data/storage/s3-vectors-wrapper-create-mutation.ts b/apps/studio/data/storage/s3-vectors-wrapper-create-mutation.tsindex 2007dbb013b..41047d0bf6c 100644--- a/apps/studio/data/storage/s3-vectors-wrapper-create-mutation.ts+++ b/apps/studio/data/storage/s3-vectors-wrapper-create-mutation.ts@@ -4,6 +4,7 @@ import { WRAPPERS } from 'components/interfaces/Integrations/Wrappers/Wrappers.cimport { getVectorURI } from 'components/interfaces/Storage/StorageSettings/StorageSettings.utils'import {getVectorBucketFDWName,+ getVectorBucketFDWSchemaName,getVectorBucketS3KeyName,} from 'components/interfaces/Storage/VectorBuckets/VectorBuckets.utils'import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'@@ -50,6 +51,7 @@ export const useS3VectorsWrapperCreateMutation = () => {vault_secret_access_key: createS3KeyData?.secret_key,aws_region: settings!.region,endpoint_url: getVectorURI(project?.ref ?? '', protocol, endpoint),+ supabase_target_schema: getVectorBucketFDWSchemaName(bucketName),},mode: 'skip',tables: [],diff --git a/apps/studio/hooks/useProtectedSchemas.ts b/apps/studio/hooks/useProtectedSchemas.tsindex 49024dcac51..1d310340e7b 100644--- a/apps/studio/hooks/useProtectedSchemas.ts+++ b/apps/studio/hooks/useProtectedSchemas.ts@@ -1,7 +1,10 @@-import { uniq } from 'lodash'+import { uniq, uniqBy } from 'lodash'import { useMemo } from 'react'-import { WRAPPER_HANDLERS } from 'components/interfaces/Integrations/Wrappers/Wrappers.constants'+import {+ SUPABASE_TARGET_SCHEMA_OPTION,+ WRAPPERS,+} from 'components/interfaces/Integrations/Wrappers/Wrappers.constants'import {convertKVStringArrayToJson,wrapperMetaComparator,@@ -34,35 +37,56 @@ export const INTERNAL_SCHEMAS = []/**- * Get the list of schemas used by IcebergFDWs+ * Get the list of schemas used by FDWs like Iceberg, S3 Vectors, etc.*/-const useIcebergFdwSchemasQuery = () => {+const useFdwSchemasQuery = () => {const { data: project } = useSelectedProjectQuery()const result = useFDWsQuery({projectRef: project?.ref,connectionString: project?.connectionString,})+ // Find all wrappers that create a schema for their data.+ const FDWsWithSchemas = useMemo(+ () =>+ WRAPPERS.filter((wrapper) =>+ wrapper.server.options.some((option) => option.name === SUPABASE_TARGET_SCHEMA_OPTION.name)+ ),+ []+ )+const schemas = useMemo(() => {- const icebergFDWs = result.data?.filter((wrapper) =>- wrapperMetaComparator(- { handlerName: WRAPPER_HANDLERS.ICEBERG, server: { options: [] } },- wrapper- )- )+ const icebergFDWs =+ result.data?.filter((wrapper) =>+ FDWsWithSchemas.some((w) => wrapperMetaComparator(w, wrapper))+ ) ?? []++ const fdwSchemas = icebergFDWs.map((fdw) => {+ const schemaOption =+ convertKVStringArrayToJson(fdw.server_options)['supabase_target_schema'] ?? ''- const fdwSchemas = icebergFDWs- ?.map((fdw) => convertKVStringArrayToJson(fdw.server_options))- .map((options) => options['supabase_target_schema'])- .flatMap((s) => s?.split(','))- .filter(Boolean)+ const schemas = uniq(schemaOption.split(',').filter(Boolean))- return uniq(fdwSchemas)- }, [result.data])+ return {+ serverName: fdw.server_name,+ type: fdw.handler.replace('_fdw_handler', ''),+ schemas,+ }+ })++ return fdwSchemas+ }, [result.data, FDWsWithSchemas])return { ...result, data: schemas }}+type ProtectedSchema = {+ name: string+ type: 'fdw' | 'internal'+ fdwType?: string+ serverName?: string+}+/*** Returns a list of schemas that are protected by Supabase (internal schemas or schemas used by Iceberg FDWs).*/@@ -73,13 +97,20 @@ export const useProtectedSchemas = ({// eslint-disable-next-line react-hooks/exhaustive-depsconst stableExcludeSchemas = useMemo(() => excludeSchemas, [JSON.stringify(excludeSchemas)])- const result = useIcebergFdwSchemasQuery()+ const result = useFdwSchemasQuery()- const schemas = useMemo<{ name: string; type: 'fdw' | 'internal' }[]>(() => {+ const schemas = useMemo<ProtectedSchema[]>(() => {const internalSchemas = INTERNAL_SCHEMAS.map((s) => ({ name: s, type: 'internal' as const }))- const icebergFdwSchemas = result.data?.map((s) => ({ name: s, type: 'fdw' as const }))+ const fdwSchemas = result.data?.flatMap((s) =>+ s.schemas.map((schema) => ({+ name: schema,+ type: 'fdw' as const,+ fdwType: s.type,+ serverName: s.serverName,+ }))+ )- const schemas = uniq([...internalSchemas, ...icebergFdwSchemas])+ const schemas = uniqBy([...internalSchemas, ...fdwSchemas], (s) => s.name)return schemas.filter((schema) => !stableExcludeSchemas.includes(schema.name))}, [result.data, stableExcludeSchemas])@@ -96,8 +127,8 @@ export const useIsProtectedSchema = ({schema: stringexcludedSchemas?: string[]}):- | { isSchemaLocked: false; reason: undefined }- | { isSchemaLocked: true; reason: 'fdw' | 'internal' } => {+ | { isSchemaLocked: false; reason: undefined; fdwType: undefined }+ | { isSchemaLocked: true; reason: 'internal' | 'fdw'; fdwType: string | undefined } => {const { data: schemas } = useProtectedSchemas({ excludeSchemas: excludedSchemas })const foundSchema = schemas.find((s) => s.name === schema)@@ -106,7 +137,8 @@ export const useIsProtectedSchema = ({return {isSchemaLocked: true,reason: foundSchema.type,+ fdwType: foundSchema.fdwType,}}- return { isSchemaLocked: false, reason: undefined }+ return { isSchemaLocked: false, reason: undefined, fdwType: undefined }}