Files
supabase/apps/studio/data/config/project-storage-config-query.ts
Joshen Lim 1d203f6c93 feat: Support CLI for Vector buckets (#46381)
## Context

> [!IMPORTANT]  
> Will open up for review once CLI PR is merged and deployed so that
it's easier to test

Related PR: https://github.com/supabase/cli/pull/5230

Adding support for vector buckets for local CLI - will need to be tested
locally via `pnpm run dev:studio-local`

## To test
There's a bit of testing instructions in the linear ticket
[here](https://linear.app/supabase/issue/FE-3474/show-vector-buckets-in-local-admin-studio)
as it involves using a branch of CLI - otherwise do reach out to
Fabrizio if any help might be needed, but generally:

### Local CLI
You might need to manually set `isCli` to `true` in `StorageMenuV2` if
the "Vectors" nav item isn't showing up on the storage UI given we're
testing via `pnpm run dev:studio-local`
- [x] Can create bucket
- [x] Can delete bucket
- [x] Can create indexes
- [x] Can insert data into indexes (via FDW)
- [x] Can delete indexes

Known issues (that aren't directly solvable from FE end)
Reach out to Fabrizio for context as we were both investigating this
- PG database needs to be on 17.6 (otherwise there's no S3 vectors FDW)
- Storage version needs to be on 1.59.0

### Self-hosted (This might be tricky to actually test, but just ensure
that the code satisfies this)
- [x] Cannot see vector buckets

### Hosted
- [x] Everything works status quo

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Vector bucket management UI and platform APIs (create/list/delete
buckets & indexes)
* Local S3 credentials endpoint and client-side hook for self‑hosted/CLI
use

* **Bug Fixes**
* Improved S3 vector setup notifications and clearer error guidance for
manual installation

* **Refactor**
* Deployment-mode gating: platform vs CLI/self‑hosted now controls
feature visibility and page behavior

* **Tests**
* Added suites covering deployment-mode gates and vector bucket
error/usage scenarios

* **Chores**
  * Build env updated to expose local S3 credential vars

<!-- 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/46381?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 -->

---------

Co-authored-by: Ali Waseem <waseema393@gmail.com>
2026-06-01 08:02:22 -06:00

69 lines
2.5 KiB
TypeScript

import { useQuery } from '@tanstack/react-query'
import { configKeys } from './keys'
import { components } from '@/data/api'
import { get, handleError } from '@/data/fetchers'
import { useDeploymentMode } from '@/hooks/misc/useDeploymentMode'
import { IS_PLATFORM } from '@/lib/constants'
import type { ResponseError, UseCustomQueryOptions } from '@/types'
export type ProjectStorageConfigVariables = {
projectRef?: string
}
export type ProjectStorageConfigResponse = components['schemas']['StorageConfigResponse']
export async function getProjectStorageConfig(
{ projectRef }: ProjectStorageConfigVariables,
signal?: AbortSignal
) {
if (!projectRef) throw new Error('projectRef is required')
const { data, error } = await get('/platform/projects/{ref}/config/storage', {
params: { path: { ref: projectRef } },
signal,
})
if (error) {
// [Joshen] This is due to API not returning an error message on this endpoint if a 404 is returned
// Should only be a temporary patch, needs to be addressed on the API end
if ((error as any).code === 404) {
handleError({ ...(error as any), message: 'Storage configuration not found.' })
} else {
handleError(error)
}
}
return data
}
export type ProjectStorageConfigData = Awaited<ReturnType<typeof getProjectStorageConfig>>
export type ProjectStorageConfigError = ResponseError
export const useProjectStorageConfigQuery = <TData = ProjectStorageConfigData>(
{ projectRef }: ProjectStorageConfigVariables,
{
enabled = true,
...options
}: UseCustomQueryOptions<ProjectStorageConfigData, ProjectStorageConfigError, TData> = {}
) =>
useQuery<ProjectStorageConfigData, ProjectStorageConfigError, TData>({
queryKey: configKeys.storage(projectRef),
queryFn: ({ signal }) => getProjectStorageConfig({ projectRef }, signal),
enabled: enabled && IS_PLATFORM && typeof projectRef !== 'undefined' && projectRef !== '_',
...options,
})
export const useIsAnalyticsBucketsEnabled = ({ projectRef }: { projectRef?: string }) => {
const { data } = useProjectStorageConfigQuery({ projectRef })
const isIcebergCatalogEnabled = !!data?.features.icebergCatalog?.enabled
return isIcebergCatalogEnabled
}
export const useIsVectorBucketsEnabled = ({ projectRef }: { projectRef?: string }) => {
const { data } = useProjectStorageConfigQuery({ projectRef })
const { isCli, isPlatform } = useDeploymentMode()
const isVectorBucketsEnabled = isCli || (isPlatform && !!data?.features.vectorBuckets?.enabled)
return isVectorBucketsEnabled
}