mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35:10 +03:00
Add support for connection string for warehouse. This PR gives the ability to enable warehouse on a project and also get the connection string to connect to. > This project is only available in staging for now and gated behind a feature flag <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added a Warehouse connection option to the Connect dialog. - Select schemas and tables to replicate, with setup progress, error recovery, and retry support. - View copyable Warehouse connection details, credentials guidance, command-line instructions, and DuckLake setup scripts. - Warehouse availability is controlled by feature configuration. - **Tests** - Added coverage for Warehouse table selection, setup script generation, URL parsing, and connection configuration utilities. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com> Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com>
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
import { components } from 'api-types'
|
|
import { toast } from 'sonner'
|
|
|
|
import { warehouseKeys } from './keys'
|
|
import { handleError, post } from '@/data/fetchers'
|
|
import type { ResponseError, UseCustomMutationOptions } from '@/types'
|
|
|
|
export type UpdateWarehouseCatalogBody = components['schemas']['UpdateWarehouseCatalogBody']
|
|
|
|
export type UpdateWarehouseCatalogVariables = {
|
|
projectRef: string
|
|
body: UpdateWarehouseCatalogBody
|
|
}
|
|
|
|
async function updateWarehouseCatalog({ projectRef, body }: UpdateWarehouseCatalogVariables) {
|
|
if (!projectRef) throw new Error('projectRef is required')
|
|
|
|
const { data, error } = await post('/platform/warehouse/{ref}/catalog', {
|
|
params: { path: { ref: projectRef } },
|
|
body,
|
|
})
|
|
if (error) {
|
|
handleError(error)
|
|
}
|
|
|
|
return data
|
|
}
|
|
|
|
export type UpdateWarehouseCatalogData = Awaited<ReturnType<typeof updateWarehouseCatalog>>
|
|
|
|
export const useUpdateWarehouseCatalogMutation = ({
|
|
onSuccess,
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseCustomMutationOptions<
|
|
UpdateWarehouseCatalogData,
|
|
ResponseError,
|
|
UpdateWarehouseCatalogVariables
|
|
>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation<UpdateWarehouseCatalogData, ResponseError, UpdateWarehouseCatalogVariables>({
|
|
mutationFn: (vars) => updateWarehouseCatalog(vars),
|
|
async onSuccess(data, variables, context) {
|
|
await queryClient.invalidateQueries({
|
|
queryKey: warehouseKeys.catalog(variables.projectRef),
|
|
})
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
async onError(error, variables, context) {
|
|
if (onError === undefined) {
|
|
toast.error(`Failed to update Warehouse catalog access: ${error.message}`)
|
|
} else {
|
|
onError(error, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
})
|
|
}
|