Files
supabase/apps/studio/data/replication/create-destination-pipeline-mutation.ts
Victor FarazdagiandJoshen Lim 00adb5a81b chore(studio): remove the Iceberg pipeline destination (#52229)
## Problem

Retire the deprecated Iceberg (Analytics Bucket) destination from
Pipelines.

## Solution

- Remove the destination UI, configuration mappings, feature-flag usage,
and generated API variants.
- Remove the legacy Pipelines integration from Storage while preserving
standalone Analytics Buckets.
- Remove unused components and sheet-layout support, and add regression
coverage for retained Storage operations.
- Remove the stale Pipelines claim from the Storage docs overview.

## Validation

- Pipelines, Storage, and replication data tests
- After the final cleanup: Studio typecheck and all 3 Analytics Bucket
regression tests passed.
- Formatting, scoped ESLint, Knip, and whitespace checks passed; lint
warnings are pre-existing.
- Storage overview: Prettier, ESLint with zero warnings, content-listing
schema validation, and Markdown rendering passed.

Production API-type verification remains pending the coordinated API
deployment. Legacy Iceberg pipelines, destinations, and slots must be
cleaned up before rollout.

## Review instructions

1. Verify that Pipelines offers BigQuery, DuckLake, Snowflake, and
ClickHouse, with no Analytics Bucket option.
2. Verify that Storage Analytics Bucket creation, namespace/table
operations, and wrapper/key cleanup remain available without Pipelines
controls.

## Checklist

- [x] Read CONTRIBUTING.md.
- [x] Updated the Storage overview copy and checked the docs authoring
guidance.

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2026-11-11 12:18:04 +03:00

210 lines
6.6 KiB
TypeScript

import { useMutation, useQueryClient } from '@tanstack/react-query'
import type { components } from 'api-types'
import { toast } from 'sonner'
import { invalidateReplicationPipelineQueries } from './invalidate-pipeline-queries'
import { replicationKeys } from './keys'
import { pipelineIdSchema } from './pipeline-id'
import type {
BigQueryDestinationConfig,
BigQueryTableOption,
DestinationConfig,
DucklakeDestinationConfig,
PipelineConfig,
} from './types'
import {
buildBigQueryTableOptionApiConfig,
buildPipelineApiConfig,
getConfiguredBigQueryTableOptions,
isDucklakeSupabaseConfig,
} from './utils'
import { handleError, post } from '@/data/fetchers'
import type { StudioError } from '@/lib/errors/studio-errors'
import type { UseCustomMutationOptions } from '@/types'
type CreateDestinationPipelineBody =
components['schemas']['CreateReplicationDestinationPipelineBody']
type CreateDestinationApiConfig = CreateDestinationPipelineBody['destination_config']
type CreateBigQueryApiConfig = Extract<CreateDestinationApiConfig, { big_query: unknown }>
type CreateDucklakeApiConfig = Extract<CreateDestinationApiConfig, { ducklake: unknown }>
const buildBigQueryTableOptionsApiConfig = (tableOptions: BigQueryTableOption[] | undefined) => {
const configuredTableOptions = getConfiguredBigQueryTableOptions(tableOptions)
if (tableOptions === undefined || configuredTableOptions.length === 0) return undefined
return { tables: configuredTableOptions.map(buildBigQueryTableOptionApiConfig) }
}
// Maps the studio-side BigQuery config to the snake_case `{ big_query: ... }` payload accepted
// by the platform API. Shared by the create and validate mutations.
export function buildBigQueryApiConfig(config: BigQueryDestinationConfig): CreateBigQueryApiConfig {
return {
big_query: {
project_id: config.projectId,
dataset_id: config.datasetId,
service_account_key: config.serviceAccountKey,
connection_pool_size: config.connectionPoolSize,
max_staleness_mins: config.maxStalenessMins,
table_options: buildBigQueryTableOptionsApiConfig(config.tableOptions),
},
}
}
// Maps the studio-side DuckLake config to the snake_case `{ ducklake: ... }` payload accepted
// by the platform API. Shared by the create / update / validate mutations.
export function buildDucklakeApiConfig(config: DucklakeDestinationConfig): CreateDucklakeApiConfig {
if (isDucklakeSupabaseConfig(config)) {
return {
ducklake: {
// pool_size / metadata_schema live on the catalog so they apply to the selected
// Supabase Postgres catalog (the API resolves catalog-level values over top-level).
catalog: {
type: 'supabase_project',
project_ref: config.catalogProjectRef,
pool_size: config.poolSize,
metadata_schema: config.metadataSchema,
},
storage: {
type: 'supabase_storage',
project_ref: config.storageProjectRef,
bucket: config.bucket,
...(config.path ? { path: config.path } : {}),
},
},
}
}
return {
ducklake: {
catalog_url: config.catalogUrl,
data_path: config.dataPath,
pool_size: config.poolSize,
s3_access_key_id: config.s3AccessKeyId,
s3_secret_access_key: config.s3SecretAccessKey,
s3_region: config.s3Region,
s3_endpoint: config.s3Endpoint,
s3_url_style: config.s3UrlStyle,
s3_use_ssl: config.s3UseSsl,
metadata_schema: config.metadataSchema,
},
}
}
export const buildCreateDestinationApiConfig = (
destinationConfig: DestinationConfig
): CreateDestinationApiConfig => {
if ('bigQuery' in destinationConfig) {
return buildBigQueryApiConfig(destinationConfig.bigQuery)
}
if ('ducklake' in destinationConfig) {
return buildDucklakeApiConfig(destinationConfig.ducklake)
}
if ('snowflake' in destinationConfig) {
const { accountId, user, privateKey, privateKeyPassphrase, database, schema, role } =
destinationConfig.snowflake
return {
snowflake: {
account_id: accountId,
user,
private_key: privateKey,
private_key_passphrase: privateKeyPassphrase,
database,
schema,
role,
},
}
}
if ('clickHouse' in destinationConfig) {
const { url, user, password, database, engine } = destinationConfig.clickHouse
return { clickhouse: { url, user, password, database, engine } }
}
throw new Error(
'Invalid destination config: must specify bigQuery, ducklake, snowflake, or clickHouse'
)
}
export type CreateDestinationPipelineParams = {
projectRef: string
destinationName: string
destinationConfig: DestinationConfig
sourceId: number
pipelineConfig: PipelineConfig
}
async function createDestinationPipeline(
{
projectRef,
destinationName: destinationName,
destinationConfig,
pipelineConfig,
sourceId,
}: CreateDestinationPipelineParams,
signal?: AbortSignal
) {
if (!projectRef) throw new Error('projectRef is required')
const destination_config = buildCreateDestinationApiConfig(destinationConfig)
const pipeline_config = buildPipelineApiConfig(pipelineConfig)
const { data, error } = await post('/platform/replication/{ref}/destinations-pipelines', {
params: { path: { ref: projectRef } },
body: {
source_id: sourceId,
destination_name: destinationName,
destination_config,
pipeline_config,
},
signal,
})
if (error) handleError(error)
return { ...data, pipeline_id: pipelineIdSchema.parse(data.pipeline_id) }
}
type CreateDestinationPipelineData = Awaited<ReturnType<typeof createDestinationPipeline>>
export const useCreateDestinationPipelineMutation = ({
onSuccess,
onError,
...options
}: Omit<
UseCustomMutationOptions<
CreateDestinationPipelineData,
StudioError,
CreateDestinationPipelineParams
>,
'mutationFn'
> = {}) => {
const queryClient = useQueryClient()
return useMutation<CreateDestinationPipelineData, StudioError, CreateDestinationPipelineParams>({
mutationFn: (vars) => createDestinationPipeline(vars),
async onSuccess(data, variables, context) {
const { projectRef } = variables
await Promise.all([
queryClient.invalidateQueries({ queryKey: replicationKeys.destinations(projectRef) }),
invalidateReplicationPipelineQueries(queryClient, projectRef),
])
await onSuccess?.(data, variables, context)
},
async onError(data, variables, context) {
if (onError === undefined) {
toast.error(`Failed to create destination or pipeline: ${data.message}`)
} else {
onError(data, variables, context)
}
},
...options,
})
}