mirror of
https://github.com/supabase/supabase.git
synced 2026-09-07 18:38:50 +08:00
## What kind of change does this PR introduce? Studio data-layer refactor. ## What is the current behavior? Pipeline creation, editing, and validation build similar destination and pipeline payloads separately. The duplicated mappings rely on type assertions and can drift between actions. ## What is the new behavior? Uses shared typed builders for create, update, and validation payloads across the existing destinations. Update payloads continue to omit blank secrets, while create payloads preserve their current values. This PR does not add table partitioning configuration. ## To test This is a data-layer refactor. No visible behaviour should change. 1. Open **Database > Replication** and click **Start a new pipeline**. 2. Select **BigQuery**, or any other enabled destination. 3. Edit a few non-secret fields and expand **Advanced settings**. 4. Confirm the form remains usable and no runtime errors appear. Create, update, validation, and secret-handling behaviour is covered by the focused tests and CI. Deploy previews and fresh local projects do not have the existing destinations or credentials needed to exercise those paths manually. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved replication destination configuration handling during creation, updates, and validation. * Applied consistent configuration mapping across supported destination types. * Ensured blank secret values are omitted during updates while retained when creating destinations. * Standardized table synchronization defaults when no specific setting is provided. * **Tests** * Added coverage for BigQuery configuration mapping and secret handling. * Updated DuckLake tests for destination updates. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
78 lines
2.5 KiB
TypeScript
78 lines
2.5 KiB
TypeScript
import { useMutation } from '@tanstack/react-query'
|
|
import type { components } from 'api-types'
|
|
|
|
import { buildCreateDestinationApiConfig } from './create-destination-pipeline-mutation'
|
|
import type { DestinationConfig, TableSyncCopyConfig } from './types'
|
|
import { buildPipelineApiConfig } from './utils'
|
|
import { handleError, post } from '@/data/fetchers'
|
|
import type { ResponseError, UseCustomMutationOptions } from '@/types'
|
|
|
|
type ValidateDestinationParams = {
|
|
projectRef: string
|
|
destinationConfig: DestinationConfig
|
|
sourceId?: number
|
|
publicationName?: string
|
|
maxFillMs?: number
|
|
maxTableSyncWorkers?: number
|
|
maxCopyConnectionsPerTable?: number
|
|
invalidatedSlotBehavior?: 'error' | 'recreate'
|
|
tableSyncCopy?: TableSyncCopyConfig
|
|
}
|
|
|
|
type ValidateDestinationResponse = components['schemas']['ValidateDestinationResponse']
|
|
export type ValidationFailure = ValidateDestinationResponse['validation_failures'][number]
|
|
|
|
async function validateDestination(
|
|
{
|
|
projectRef,
|
|
destinationConfig,
|
|
sourceId,
|
|
publicationName,
|
|
maxFillMs,
|
|
maxTableSyncWorkers,
|
|
maxCopyConnectionsPerTable,
|
|
invalidatedSlotBehavior,
|
|
tableSyncCopy,
|
|
}: ValidateDestinationParams,
|
|
signal?: AbortSignal
|
|
): Promise<ValidateDestinationResponse> {
|
|
if (!projectRef) throw new Error('projectRef is required')
|
|
|
|
const { data, error } = await post('/platform/replication/{ref}/destinations/validate', {
|
|
params: { path: { ref: projectRef } },
|
|
body: {
|
|
config: buildCreateDestinationApiConfig(destinationConfig),
|
|
source_id: sourceId,
|
|
pipeline_config:
|
|
publicationName === undefined
|
|
? undefined
|
|
: buildPipelineApiConfig({
|
|
publicationName,
|
|
maxTableSyncWorkers,
|
|
maxCopyConnectionsPerTable,
|
|
invalidatedSlotBehavior,
|
|
tableSyncCopy: tableSyncCopy ?? { type: 'include_all_tables' },
|
|
batch: maxFillMs === undefined ? undefined : { maxFillMs },
|
|
}),
|
|
},
|
|
signal,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
type ValidateDestinationData = Awaited<ReturnType<typeof validateDestination>>
|
|
|
|
export const useValidateDestinationMutation = (
|
|
options?: Omit<
|
|
UseCustomMutationOptions<ValidateDestinationData, ResponseError, ValidateDestinationParams>,
|
|
'mutationFn'
|
|
>
|
|
) => {
|
|
return useMutation<ValidateDestinationData, ResponseError, ValidateDestinationParams>({
|
|
mutationFn: (vars) => validateDestination(vars),
|
|
...options,
|
|
})
|
|
}
|