mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03: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>
169 lines
4.8 KiB
TypeScript
169 lines
4.8 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import {
|
|
buildBigQueryApiConfig,
|
|
buildDucklakeApiConfig,
|
|
} from './create-destination-pipeline-mutation'
|
|
import {
|
|
buildBigQueryUpdateApiConfig,
|
|
buildDucklakeUpdateApiConfig,
|
|
} from './update-destination-pipeline-mutation'
|
|
import { buildPipelineApiConfig } from './utils'
|
|
|
|
describe('buildPipelineApiConfig', () => {
|
|
it('maps selective initial-copy configuration to the ETL API shape', () => {
|
|
expect(
|
|
buildPipelineApiConfig({
|
|
publicationName: 'analytics',
|
|
batch: { maxFillMs: 500, maxBytes: 8_388_608, memoryBudgetRatio: 0.2 },
|
|
maxTableSyncWorkers: 4,
|
|
maxCopyConnectionsPerTable: 2,
|
|
invalidatedSlotBehavior: 'recreate',
|
|
tableSyncCopy: { type: 'skip_tables', table_ids: [101, 202] },
|
|
})
|
|
).toEqual({
|
|
publication_name: 'analytics',
|
|
batch: { max_fill_ms: 500, max_bytes: 8_388_608, memory_budget_ratio: 0.2 },
|
|
max_table_sync_workers: 4,
|
|
max_copy_connections_per_table: 2,
|
|
invalidated_slot_behavior: 'recreate',
|
|
table_sync_copy: { type: 'skip_tables', table_ids: [101, 202] },
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('buildBigQueryApiConfig', () => {
|
|
const baseConfig = {
|
|
projectId: 'my-project',
|
|
datasetId: 'analytics',
|
|
serviceAccountKey: '{}',
|
|
}
|
|
|
|
it('maps the destination config to the API shape', () => {
|
|
expect(buildBigQueryApiConfig(baseConfig)).toEqual({
|
|
big_query: {
|
|
project_id: 'my-project',
|
|
dataset_id: 'analytics',
|
|
service_account_key: '{}',
|
|
connection_pool_size: undefined,
|
|
max_staleness_mins: undefined,
|
|
},
|
|
})
|
|
})
|
|
|
|
it('omits blank service_account_key on update, but not on create', () => {
|
|
const config = { ...baseConfig, serviceAccountKey: '' }
|
|
|
|
expect(buildBigQueryApiConfig(config).big_query.service_account_key).toBe('')
|
|
expect(buildBigQueryUpdateApiConfig(config).big_query.service_account_key).toBeUndefined()
|
|
})
|
|
})
|
|
|
|
describe('buildDucklakeApiConfig', () => {
|
|
it('maps a "Use Supabase" config with catalog-level pool size + metadata schema', () => {
|
|
expect(
|
|
buildDucklakeApiConfig({
|
|
catalogProjectRef: 'catalog-ref',
|
|
storageProjectRef: 'storage-ref',
|
|
bucket: 'ducklake-data',
|
|
poolSize: 4,
|
|
metadataSchema: 'ducklake',
|
|
})
|
|
).toEqual({
|
|
ducklake: {
|
|
catalog: {
|
|
type: 'supabase_project',
|
|
project_ref: 'catalog-ref',
|
|
pool_size: 4,
|
|
metadata_schema: 'ducklake',
|
|
},
|
|
storage: {
|
|
type: 'supabase_storage',
|
|
project_ref: 'storage-ref',
|
|
bucket: 'ducklake-data',
|
|
},
|
|
},
|
|
})
|
|
})
|
|
|
|
it('includes the optional path prefix when provided', () => {
|
|
const config = buildDucklakeApiConfig({
|
|
catalogProjectRef: 'catalog-ref',
|
|
storageProjectRef: 'storage-ref',
|
|
bucket: 'ducklake-data',
|
|
path: 'replication',
|
|
})
|
|
|
|
expect(config).toMatchObject({
|
|
ducklake: {
|
|
storage: {
|
|
type: 'supabase_storage',
|
|
project_ref: 'storage-ref',
|
|
bucket: 'ducklake-data',
|
|
path: 'replication',
|
|
},
|
|
},
|
|
})
|
|
})
|
|
|
|
it('maps a "Custom parameters" config to the flat snake_case payload', () => {
|
|
expect(
|
|
buildDucklakeApiConfig({
|
|
catalogUrl: 'postgres://user:pass@host:5432/catalog',
|
|
dataPath: 's3://bucket/path',
|
|
poolSize: 4,
|
|
s3AccessKeyId: 'access-key',
|
|
s3SecretAccessKey: 'secret-key',
|
|
s3Region: 'eu-west-1',
|
|
s3Endpoint: 's3.example.com',
|
|
s3UrlStyle: 'path',
|
|
s3UseSsl: true,
|
|
metadataSchema: 'ducklake',
|
|
})
|
|
).toEqual({
|
|
ducklake: {
|
|
catalog_url: 'postgres://user:pass@host:5432/catalog',
|
|
data_path: 's3://bucket/path',
|
|
pool_size: 4,
|
|
s3_access_key_id: 'access-key',
|
|
s3_secret_access_key: 'secret-key',
|
|
s3_region: 'eu-west-1',
|
|
s3_endpoint: 's3.example.com',
|
|
s3_url_style: 'path',
|
|
s3_use_ssl: true,
|
|
metadata_schema: 'ducklake',
|
|
},
|
|
})
|
|
})
|
|
|
|
it('omits blank custom secret fields when requested', () => {
|
|
expect(
|
|
buildDucklakeUpdateApiConfig({
|
|
catalogUrl: ' ',
|
|
dataPath: 's3://bucket/path',
|
|
poolSize: 4,
|
|
s3AccessKeyId: '',
|
|
s3SecretAccessKey: '\n',
|
|
s3Region: 'eu-west-1',
|
|
s3Endpoint: 's3.example.com',
|
|
s3UrlStyle: 'path',
|
|
s3UseSsl: true,
|
|
metadataSchema: 'ducklake',
|
|
})
|
|
).toEqual({
|
|
ducklake: {
|
|
catalog_url: undefined,
|
|
data_path: 's3://bucket/path',
|
|
pool_size: 4,
|
|
s3_access_key_id: undefined,
|
|
s3_secret_access_key: undefined,
|
|
s3_region: 'eu-west-1',
|
|
s3_endpoint: 's3.example.com',
|
|
s3_url_style: 'path',
|
|
s3_use_ssl: true,
|
|
metadata_schema: 'ducklake',
|
|
},
|
|
})
|
|
})
|
|
})
|