Files
supabase/apps/studio/data/warehouse/warehouse-setup-mutation.ts
T
Coenen BenjaminandCharis Lam 11289328e5 add support for warehouse connection string (#49914)
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>
2026-09-07 11:24:42 +02:00

60 lines
1.7 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 WarehouseSetupBody = components['schemas']['WarehouseSetupBody']
export type WarehouseSetupVariables = {
projectRef: string
body: WarehouseSetupBody
}
async function setupWarehouse({ projectRef, body }: WarehouseSetupVariables) {
if (!projectRef) throw new Error('projectRef is required')
const { data, error } = await post('/platform/warehouse/{ref}/setup', {
params: { path: { ref: projectRef } },
body,
})
if (error) {
handleError(error)
}
return data
}
export type WarehouseSetupData = Awaited<ReturnType<typeof setupWarehouse>>
export const useWarehouseSetupMutation = ({
onSuccess,
onError,
...options
}: Omit<
UseCustomMutationOptions<WarehouseSetupData, ResponseError, WarehouseSetupVariables>,
'mutationFn'
> = {}) => {
const queryClient = useQueryClient()
return useMutation<WarehouseSetupData, ResponseError, WarehouseSetupVariables>({
mutationFn: (vars) => setupWarehouse(vars),
async onSuccess(data, variables, context) {
await queryClient.invalidateQueries({
queryKey: warehouseKeys.setupStatus(variables.projectRef),
})
await onSuccess?.(data, variables, context)
},
async onError(error, variables, context) {
if (onError === undefined) {
toast.error(`Failed to set up Warehouse: ${error.message}`)
} else {
onError(error, variables, context)
}
},
...options,
})
}