Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat: add iceberg (analytics bucket) destination in UI (#39324)

Raminder Singha21fa43d8f78
diff --git a/apps/studio/components/interfaces/Database/Replication/ComingSoon.tsx b/apps/studio/components/interfaces/Database/Replication/ComingSoon.tsx
index c6e54a9877f..44a41e88ecb 100644
--- a/apps/studio/components/interfaces/Database/Replication/ComingSoon.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/ComingSoon.tsx
@@ -96,7 +96,7 @@ const ReplicationStaticMockup = ({ projectRef }: { projectRef: string }) => {
blank: BlankNode,
cta: () => CTANode({ projectRef }),
}),
- []
+ [projectRef]
)
return (
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/AdvancedSettings.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/AdvancedSettings.tsx
new file mode 100644
index 00000000000..4f3b864f379
--- /dev/null
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/AdvancedSettings.tsx
@@ -0,0 +1,81 @@
+import { UseFormReturn } from 'react-hook-form'
+
+import {
+ Accordion_Shadcn_,
+ AccordionContent_Shadcn_,
+ AccordionItem_Shadcn_,
+ AccordionTrigger_Shadcn_,
+ FormControl_Shadcn_,
+ FormField_Shadcn_,
+ Input_Shadcn_,
+} from 'ui'
+import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
+import { DestinationPanelSchemaType } from './DestinationPanel.schema'
+
+export const AdvancedSettings = ({ form }: { form: UseFormReturn<DestinationPanelSchemaType> }) => {
+ const { type } = form.watch()
+
+ return (
+ <Accordion_Shadcn_ type="single" collapsible>
+ <AccordionItem_Shadcn_ value="item-1" className="border-none">
+ <AccordionTrigger_Shadcn_ className="font-normal gap-2 justify-between text-sm">
+ Advanced Settings
+ </AccordionTrigger_Shadcn_>
+ <AccordionContent_Shadcn_ asChild className="!pb-0">
+ <FormField_Shadcn_
+ control={form.control}
+ name="maxFillMs"
+ render={({ field }) => (
+ <FormItemLayout
+ className="mb-4"
+ label="Max fill milliseconds"
+ layout="vertical"
+ description="The maximum amount of time to fill the data in milliseconds. Leave empty to use default value."
+ >
+ <FormControl_Shadcn_>
+ <Input_Shadcn_
+ {...field}
+ type="number"
+ value={field.value ?? ''}
+ onChange={(e) => {
+ const val = e.target.value
+ field.onChange(val === '' ? undefined : Number(val))
+ }}
+ placeholder="Leave empty for default"
+ />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+ {type === 'BigQuery' && (
+ <FormField_Shadcn_
+ control={form.control}
+ name="maxStalenessMins"
+ render={({ field }) => (
+ <FormItemLayout
+ className="mb-4"
+ label="Max staleness minutes"
+ layout="vertical"
+ description="Maximum staleness time allowed in minutes. Leave empty to use default value."
+ >
+ <FormControl_Shadcn_>
+ <Input_Shadcn_
+ {...field}
+ type="number"
+ value={field.value ?? ''}
+ onChange={(e) => {
+ const val = e.target.value
+ field.onChange(val === '' ? undefined : Number(val))
+ }}
+ placeholder="Leave empty for default"
+ />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+ )}
+ </AccordionContent_Shadcn_>
+ </AccordionItem_Shadcn_>
+ </Accordion_Shadcn_>
+ )
+}
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanel.constants.ts b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanel.constants.ts
new file mode 100644
index 00000000000..c94f883cd0e
--- /dev/null
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanel.constants.ts
@@ -0,0 +1,5 @@
+// Hardcoded value for `s3AccessKeyId` field in the form to indicate creating a new key
+export const CREATE_NEW_KEY = 'create-new'
+
+// Hardcoded value for `namespace` field in the form to indicate creating a new namespace
+export const CREATE_NEW_NAMESPACE = 'create-new-namespace'
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanel.schema.ts b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanel.schema.ts
new file mode 100644
index 00000000000..4eaa16f39c7
--- /dev/null
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanel.schema.ts
@@ -0,0 +1,63 @@
+import * as z from 'zod'
+
+const types = ['BigQuery', 'Analytics Bucket'] as const
+export const TypeEnum = z.enum(types)
+
+// [Joshen] JFYI if we plan to add another type here, I reckon we split this out into smaller components
+// then as FormSchema is getting quite complex with some fields that aren't necessary if the type is one or the other
+export const DestinationPanelFormSchema = z
+ .object({
+ // Common fields
+ type: TypeEnum,
+ name: z.string().min(1, 'Name is required'),
+ publicationName: z.string().min(1, 'Publication is required'),
+ maxFillMs: z.number().min(1, 'Max Fill milliseconds should be greater than 0').int().optional(),
+ // BigQuery fields
+ projectId: z.string().optional(),
+ datasetId: z.string().optional(),
+ serviceAccountKey: z.string().optional(),
+ maxStalenessMins: z.number().nonnegative().optional(),
+ // Analytics Bucket fields, only warehouse name and namespace are visible + editable fields
+ warehouseName: z.string().optional(),
+ namespace: z.string().optional(),
+ newNamespaceName: z.string().optional(),
+ catalogToken: z.string().optional(),
+ s3AccessKeyId: z.string().optional(),
+ s3SecretAccessKey: z.string().optional(),
+ s3Region: z.string().optional(),
+ })
+ .refine(
+ (data) => {
+ if (data.type === 'BigQuery') {
+ return (
+ data.projectId &&
+ data.projectId.length > 0 &&
+ data.datasetId &&
+ data.datasetId.length > 0 &&
+ data.serviceAccountKey &&
+ data.serviceAccountKey.length > 0
+ )
+ } else if (data.type === 'Analytics Bucket') {
+ const hasValidNamespace =
+ (data.namespace && data.namespace.length > 0) ||
+ (data.namespace === 'create-new-namespace' &&
+ data.newNamespaceName &&
+ data.newNamespaceName.length > 0)
+
+ return (
+ data.warehouseName &&
+ data.warehouseName.length > 0 &&
+ hasValidNamespace &&
+ data.s3Region &&
+ data.s3Region.length > 0
+ )
+ }
+ return true
+ },
+ {
+ message: 'All fields are required for the selected destination type',
+ path: ['projectId'],
+ }
+ )
+
+export type DestinationPanelSchemaType = z.infer<typeof DestinationPanelFormSchema>
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanel.tsx
similarity index 64%
rename from apps/studio/components/interfaces/Database/Replication/DestinationPanel.tsx
rename to apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanel.tsx
index 102a14e09fe..a4ef25e9f17 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanel.tsx
@@ -1,11 +1,15 @@
import { zodResolver } from '@hookform/resolvers/zod'
+import { snakeCase } from 'lodash'
import { useEffect, useMemo, useState } from 'react'
import { useForm } from 'react-hook-form'
import { toast } from 'sonner'
import * as z from 'zod'
import { useParams } from 'common'
+import { getCatalogURI } from 'components/interfaces/Storage/StorageSettings/StorageSettings.utils'
import { InlineLink } from 'components/ui/InlineLink'
+import { getKeys, useAPIKeysQuery } from 'data/api-keys/api-keys-query'
+import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'
import { useCheckPrimaryKeysExists } from 'data/database/primary-keys-exists-query'
import { useCreateDestinationPipelineMutation } from 'data/replication/create-destination-pipeline-mutation'
import { useReplicationDestinationByIdQuery } from 'data/replication/destination-by-id-query'
@@ -13,16 +17,14 @@ import { useReplicationPipelineByIdQuery } from 'data/replication/pipeline-by-id
import { useReplicationPublicationsQuery } from 'data/replication/publications-query'
import { useStartPipelineMutation } from 'data/replication/start-pipeline-mutation'
import { useUpdateDestinationPipelineMutation } from 'data/replication/update-destination-pipeline-mutation'
+import { useIcebergNamespaceCreateMutation } from 'data/storage/iceberg-namespace-create-mutation'
+import { useS3AccessKeyCreateMutation } from 'data/storage/s3-access-key-create-mutation'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import {
PipelineStatusRequestStatus,
usePipelineRequestStatus,
} from 'state/replication-pipeline-request-status'
import {
- Accordion_Shadcn_,
- AccordionContent_Shadcn_,
- AccordionItem_Shadcn_,
- AccordionTrigger_Shadcn_,
Button,
DialogSectionSeparator,
Form_Shadcn_,
@@ -41,28 +43,18 @@ import {
SheetHeader,
SheetSection,
SheetTitle,
- TextArea_Shadcn_,
} from 'ui'
import { Admonition } from 'ui-patterns'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
-import NewPublicationPanel from './NewPublicationPanel'
-import PublicationsComboBox from './PublicationsComboBox'
-import { ReplicationDisclaimerDialog } from './ReplicationDisclaimerDialog'
+import { NewPublicationPanel } from '../NewPublicationPanel'
+import { PublicationsComboBox } from '../PublicationsComboBox'
+import { ReplicationDisclaimerDialog } from '../ReplicationDisclaimerDialog'
+import { AdvancedSettings } from './AdvancedSettings'
+import { CREATE_NEW_KEY, CREATE_NEW_NAMESPACE } from './DestinationPanel.constants'
+import { DestinationPanelFormSchema as FormSchema, TypeEnum } from './DestinationPanel.schema'
+import { AnalyticsBucketFields, BigQueryFields } from './DestinationPanelFields'
const formId = 'destination-editor'
-const types = ['BigQuery'] as const
-const TypeEnum = z.enum(types)
-
-const FormSchema = z.object({
- type: TypeEnum,
- name: z.string().min(1, 'Name is required'),
- projectId: z.string().min(1, 'Project id is required'),
- datasetId: z.string().min(1, 'Dataset id is required'),
- serviceAccountKey: z.string().min(1, 'Service account key is required'),
- publicationName: z.string().min(1, 'Publication is required'),
- maxFillMs: z.number().min(1, 'Max Fill milliseconds should be greater than 0').int().optional(),
- maxStalenessMins: z.number().nonnegative().optional(),
-})
interface DestinationPanelProps {
visible: boolean
@@ -93,6 +85,7 @@ export const DestinationPanel = ({
const [pendingFormValues, setPendingFormValues] = useState<z.infer<typeof FormSchema> | null>(
null
)
+ const [isFormInteracting, setIsFormInteracting] = useState(false)
const { mutateAsync: createDestinationPipeline, isLoading: creatingDestinationPipeline } =
useCreateDestinationPipelineMutation({
@@ -106,6 +99,12 @@ export const DestinationPanel = ({
const { mutateAsync: startPipeline, isLoading: startingPipeline } = useStartPipelineMutation()
+ const { mutateAsync: createS3AccessKey, isLoading: isCreatingS3AccessKey } =
+ useS3AccessKeyCreateMutation()
+
+ const { mutateAsync: createNamespace, isLoading: isCreatingNamespace } =
+ useIcebergNamespaceCreateMutation()
+
const {
data: publications = [],
isLoading: isLoadingPublications,
@@ -123,24 +122,44 @@ export const DestinationPanel = ({
pipelineId: existingDestination?.pipelineId,
})
+ const { data: apiKeys } = useAPIKeysQuery({ projectRef, reveal: true })
+ const { serviceKey } = getKeys(apiKeys)
+ const catalogToken = serviceKey?.api_key ?? ''
+
+ const { data: projectSettings } = useProjectSettingsV2Query({ projectRef })
+
const defaultValues = useMemo(() => {
- const bigQueryConfig =
- destinationData && 'big_query' in destinationData.config
- ? destinationData?.config.big_query
- : null
+ // Type guards to safely access union properties
+ const config = destinationData?.config
+ const isBigQueryConfig = config && 'big_query' in config
+ const isIcebergConfig = config && 'iceberg' in config
return {
- type: TypeEnum.enum.BigQuery,
+ // Common fields
+ type: (isBigQueryConfig
+ ? TypeEnum.enum.BigQuery
+ : isIcebergConfig
+ ? TypeEnum.enum['Analytics Bucket']
+ : TypeEnum.enum.BigQuery) as z.infer<typeof TypeEnum>,
name: destinationData?.name ?? '',
- projectId: bigQueryConfig?.project_id ?? '',
- datasetId: bigQueryConfig?.dataset_id ?? '',
- // For now, the password will always be set as empty for security reasons.
- serviceAccountKey: bigQueryConfig?.service_account_key ?? '',
publicationName: pipelineData?.config.publication_name ?? '',
maxFillMs: pipelineData?.config?.batch?.max_fill_ms,
- maxStalenessMins: bigQueryConfig?.max_staleness_mins,
+ // BigQuery fields
+ projectId: isBigQueryConfig ? config.big_query.project_id : '',
+ datasetId: isBigQueryConfig ? config.big_query.dataset_id : '',
+ serviceAccountKey: isBigQueryConfig ? config.big_query.service_account_key : '',
+ maxStalenessMins: isBigQueryConfig ? config.big_query.max_staleness_mins : undefined,
+ // Analytics Bucket fields
+ warehouseName: isIcebergConfig ? config.iceberg.supabase.warehouse_name : '',
+ namespace: isIcebergConfig ? config.iceberg.supabase.namespace : '',
+ newNamespaceName: '',
+ catalogToken: isIcebergConfig ? config.iceberg.supabase.catalog_token : catalogToken,
+ s3AccessKeyId: isIcebergConfig ? config.iceberg.supabase.s3_access_key_id : '',
+ s3SecretAccessKey: isIcebergConfig ? config.iceberg.supabase.s3_secret_access_key : '',
+ s3Region:
+ projectSettings?.region ?? (isIcebergConfig ? config.iceberg.supabase.s3_region : ''),
}
- }, [destinationData, pipelineData])
+ }, [destinationData, pipelineData, catalogToken, projectSettings])
const form = useForm<z.infer<typeof FormSchema>>({
mode: 'onBlur',
@@ -148,8 +167,13 @@ export const DestinationPanel = ({
resolver: zodResolver(FormSchema),
defaultValues,
})
- const publicationName = form.watch('publicationName')
- const isSaving = creatingDestinationPipeline || updatingDestinationPipeline || startingPipeline
+ const { publicationName, type: selectedType, warehouseName } = form.watch()
+ const isSaving =
+ creatingDestinationPipeline ||
+ updatingDestinationPipeline ||
+ startingPipeline ||
+ isCreatingS3AccessKey ||
+ isCreatingNamespace
const publicationNames = useMemo(() => publications?.map((pub) => pub.name) ?? [], [publications])
const isSelectedPublicationMissing =
@@ -169,6 +193,35 @@ export const DestinationPanel = ({
const isSubmitDisabled =
isSaving || isSelectedPublicationMissing || isLoadingCheck || hasTablesWithNoPrimaryKeys
+ // Helper function to handle namespace creation if needed
+ const resolveNamespace = async (data: z.infer<typeof FormSchema>) => {
+ if (data.namespace === CREATE_NEW_NAMESPACE) {
+ if (!data.newNamespaceName) {
+ throw new Error('New namespace name is required')
+ }
+
+ // Construct catalog URI for namespace creation
+ const protocol = projectSettings?.app_config?.protocol ?? 'https'
+ const endpoint =
+ projectSettings?.app_config?.storage_endpoint || projectSettings?.app_config?.endpoint
+ const catalogUri = getCatalogURI(project?.ref ?? '', protocol, endpoint)
+
+ await createNamespace({
+ catalogUri,
+ warehouse: data.warehouseName!,
+ token: catalogToken,
+ namespace: data.newNamespaceName,
+ })
+
+ return data.newNamespaceName
+ }
+ return data.namespace
+ }
+
+ // [Joshen] I reckon this function can be refactored to be a bit more modular, it's currently pretty
+ // complicated with 4 different types of flows -> edit bigquery/analytics, and create bigquery/analytics
+ // At first glance we could try grouping as edit / create bigquery, edit / create analytics
+ // since the destination config seems rather similar between edit and create for the same type
const submitPipeline = async (data: z.infer<typeof FormSchema>) => {
if (!projectRef) return console.error('Project ref is required')
if (!sourceId) return console.error('Source id is required')
@@ -180,13 +233,42 @@ export const DestinationPanel = ({
if (editMode && existingDestination) {
if (!existingDestination.pipelineId) return console.error('Pipeline id is required')
- const bigQueryConfig: any = {
- projectId: data.projectId,
- datasetId: data.datasetId,
- serviceAccountKey: data.serviceAccountKey,
- }
- if (!!data.maxStalenessMins) {
- bigQueryConfig.maxStalenessMins = data.maxStalenessMins
+ let destinationConfig: any = {}
+
+ if (data.type === 'BigQuery') {
+ const bigQueryConfig: any = {
+ projectId: data.projectId,
+ datasetId: data.datasetId,
+ serviceAccountKey: data.serviceAccountKey,
+ }
+ if (!!data.maxStalenessMins) {
+ bigQueryConfig.maxStalenessMins = data.maxStalenessMins
+ }
+ destinationConfig = { bigQuery: bigQueryConfig }
+ } else if (data.type === 'Analytics Bucket') {
+ let s3Keys = { accessKey: data.s3AccessKeyId, secretKey: data.s3SecretAccessKey }
+
+ if (data.s3AccessKeyId === CREATE_NEW_KEY) {
+ const newKeys = await createS3AccessKey({
+ projectRef,
+ description: `Autogenerated key for replication to ${snakeCase(warehouseName)}`,
+ })
+ s3Keys = { accessKey: newKeys.access_key, secretKey: newKeys.secret_key }
+ }
+
+ // Resolve namespace (create if needed)
+ const finalNamespace = await resolveNamespace(data)
+
+ const icebergConfig: any = {
+ projectRef: projectRef,
+ warehouseName: data.warehouseName,
+ namespace: finalNamespace,
+ catalogToken: data.catalogToken,
+ s3AccessKeyId: s3Keys.accessKey,
+ s3SecretAccessKey: s3Keys.secretKey,
+ s3Region: data.s3Region,
+ }
+ destinationConfig = { iceberg: icebergConfig }
}
const batchConfig: any = {}
@@ -198,7 +280,7 @@ export const DestinationPanel = ({
pipelineId: existingDestination.pipelineId,
projectRef,
destinationName: data.name,
- destinationConfig: { bigQuery: bigQueryConfig },
+ destinationConfig,
pipelineConfig: {
publicationName: data.publicationName,
...(hasBatchFields ? { batch: batchConfig } : {}),
@@ -226,15 +308,43 @@ export const DestinationPanel = ({
startPipeline({ projectRef, pipelineId: existingDestination.pipelineId })
onClose()
} else {
- const bigQueryConfig: any = {
- projectId: data.projectId,
- datasetId: data.datasetId,
- serviceAccountKey: data.serviceAccountKey,
+ let destinationConfig: any = {}
+
+ if (data.type === 'BigQuery') {
+ const bigQueryConfig: any = {
+ projectId: data.projectId,
+ datasetId: data.datasetId,
+ serviceAccountKey: data.serviceAccountKey,
+ }
+ if (!!data.maxStalenessMins) {
+ bigQueryConfig.maxStalenessMins = data.maxStalenessMins
+ }
+ destinationConfig = { bigQuery: bigQueryConfig }
+ } else if (data.type === 'Analytics Bucket') {
+ let s3Keys = { accessKey: data.s3AccessKeyId, secretKey: data.s3SecretAccessKey }
+
+ if (data.s3AccessKeyId === CREATE_NEW_KEY) {
+ const newKeys = await createS3AccessKey({
+ projectRef,
+ description: `Autogenerated key for replication to ${snakeCase(warehouseName)}`,
+ })
+ s3Keys = { accessKey: newKeys.access_key, secretKey: newKeys.secret_key }
+ }
+
+ // Resolve namespace (create if needed)
+ const finalNamespace = await resolveNamespace(data)
+
+ const icebergConfig: any = {
+ projectRef: projectRef,
+ warehouseName: data.warehouseName,
+ namespace: finalNamespace,
+ catalogToken: data.catalogToken,
+ s3AccessKeyId: s3Keys.accessKey,
+ s3SecretAccessKey: s3Keys.secretKey,
+ s3Region: data.s3Region,
+ }
+ destinationConfig = { iceberg: icebergConfig }
}
- if (!!data.maxStalenessMins) {
- bigQueryConfig.maxStalenessMins = data.maxStalenessMins
- }
-
const batchConfig: any = {}
if (!!data.maxFillMs) batchConfig.maxFillMs = data.maxFillMs
const hasBatchFields = Object.keys(batchConfig).length > 0
@@ -242,7 +352,7 @@ export const DestinationPanel = ({
const { pipeline_id: pipelineId } = await createDestinationPipeline({
projectRef,
destinationName: data.name,
- destinationConfig: { bigQuery: bigQueryConfig },
+ destinationConfig,
sourceId,
pipelineConfig: {
publicationName: data.publicationName,
@@ -288,15 +398,16 @@ export const DestinationPanel = ({
}
useEffect(() => {
- if (editMode && destinationData && pipelineData) {
+ if (editMode && destinationData && pipelineData && !isFormInteracting) {
form.reset(defaultValues)
}
- }, [destinationData, pipelineData, editMode, defaultValues, form])
+ }, [destinationData, pipelineData, editMode, defaultValues, form, isFormInteracting])
// Ensure the form always reflects the freshest data whenever the panel opens
useEffect(() => {
if (visible) {
form.reset(defaultValues)
+ setIsFormInteracting(false)
}
}, [visible, defaultValues, form])
@@ -399,8 +510,8 @@ export const DestinationPanel = ({
<DialogSectionSeparator />
- <div className="p-5 flex flex-col gap-y-4">
- <p className="text-sm text-foreground-light">Where to send that data</p>
+ <div className="py-5 flex flex-col gap-y-4">
+ <p className="px-5 text-sm text-foreground-light">Where to send that data</p>
<FormField_Shadcn_
name="type"
control={form.control}
@@ -408,14 +519,24 @@ export const DestinationPanel = ({
<FormItemLayout
label="Type"
layout="vertical"
+ className="px-5"
description="The type of destination to send the data to"
>
<FormControl_Shadcn_>
- <Select_Shadcn_ value={field.value}>
+ <Select_Shadcn_
+ value={field.value}
+ onValueChange={(value) => {
+ setIsFormInteracting(true)
+ field.onChange(value)
+ }}
+ >
<SelectTrigger_Shadcn_>{field.value}</SelectTrigger_Shadcn_>
<SelectContent_Shadcn_>
<SelectGroup_Shadcn_>
<SelectItem_Shadcn_ value="BigQuery">BigQuery</SelectItem_Shadcn_>
+ <SelectItem_Shadcn_ value="Analytics Bucket">
+ Analytics Bucket
+ </SelectItem_Shadcn_>
</SelectGroup_Shadcn_>
</SelectContent_Shadcn_>
</Select_Shadcn_>
@@ -424,122 +545,25 @@ export const DestinationPanel = ({
)}
/>
- <FormField_Shadcn_
- control={form.control}
- name="projectId"
- render={({ field }) => (
- <FormItemLayout
- label="Project ID"
- layout="vertical"
- description="Which BigQuery project to send data to"
- >
- <FormControl_Shadcn_>
- <Input_Shadcn_ {...field} placeholder="Project ID" />
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
- />
-
- <FormField_Shadcn_
- control={form.control}
- name="datasetId"
- render={({ field }) => (
- <FormItemLayout label="Project's Dataset ID" layout="vertical">
- <FormControl_Shadcn_>
- <Input_Shadcn_ {...field} placeholder="Dataset ID" />
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
- />
-
- <FormField_Shadcn_
- control={form.control}
- name="serviceAccountKey"
- render={({ field }) => (
- <FormItemLayout
- label="Service Account Key"
- layout="vertical"
- description="The service account key for BigQuery"
- >
- <FormControl_Shadcn_>
- <TextArea_Shadcn_
- {...field}
- rows={4}
- maxLength={5000}
- placeholder="Service account key"
- />
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
- />
+ {selectedType === 'BigQuery' ? (
+ <BigQueryFields form={form} />
+ ) : selectedType === 'Analytics Bucket' ? (
+ <AnalyticsBucketFields
+ form={form}
+ setIsFormInteracting={setIsFormInteracting}
+ />
+ ) : null}
</div>
<DialogSectionSeparator />
<div className="px-5">
- <Accordion_Shadcn_ type="single" collapsible>
- <AccordionItem_Shadcn_ value="item-1" className="border-none">
- <AccordionTrigger_Shadcn_ className="font-normal gap-2 justify-between text-sm">
- Advanced Settings
- </AccordionTrigger_Shadcn_>
- <AccordionContent_Shadcn_ asChild className="!pb-0">
- <FormField_Shadcn_
- control={form.control}
- name="maxFillMs"
- render={({ field }) => (
- <FormItemLayout
- className="mb-4"
- label="Max fill milliseconds"
- layout="vertical"
- description="The maximum amount of time to fill the data in milliseconds. Leave empty to use default value."
- >
- <FormControl_Shadcn_>
- <Input_Shadcn_
- {...field}
- type="number"
- value={field.value ?? ''}
- onChange={(e) => {
- const val = e.target.value
- field.onChange(val === '' ? undefined : Number(val))
- }}
- placeholder="Leave empty for default"
- />
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
- />
- <FormField_Shadcn_
- control={form.control}
- name="maxStalenessMins"
- render={({ field }) => (
- <FormItemLayout
- className="mb-4"
- label="Max staleness minutes"
- layout="vertical"
- description="Maximum staleness time allowed in minutes. Leave empty to use default value."
- >
- <FormControl_Shadcn_>
- <Input_Shadcn_
- {...field}
- type="number"
- value={field.value ?? ''}
- onChange={(e) => {
- const val = e.target.value
- field.onChange(val === '' ? undefined : Number(val))
- }}
- placeholder="Leave empty for default"
- />
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
- />
- </AccordionContent_Shadcn_>
- </AccordionItem_Shadcn_>
- </Accordion_Shadcn_>
+ <AdvancedSettings form={form} />
</div>
</form>
</Form_Shadcn_>
</SheetSection>
+
<SheetFooter>
<Button disabled={isSaving} type="default" onClick={onClose}>
Cancel
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanelFields.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanelFields.tsx
new file mode 100644
index 00000000000..c5c855e8707
--- /dev/null
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanelFields.tsx
@@ -0,0 +1,494 @@
+import { Eye, EyeOff, Loader2 } from 'lucide-react'
+import { useMemo, useState } from 'react'
+import { UseFormReturn } from 'react-hook-form'
+
+import { useParams } from 'common'
+import { useIsNewStorageUIEnabled } from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'
+import { getCatalogURI } from 'components/interfaces/Storage/StorageSettings/StorageSettings.utils'
+import { InlineLink } from 'components/ui/InlineLink'
+import { getKeys, useAPIKeysQuery } from 'data/api-keys/api-keys-query'
+import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'
+import { useBucketsQuery } from 'data/storage/buckets-query'
+import { useIcebergNamespacesQuery } from 'data/storage/iceberg-namespaces-query'
+import { useStorageCredentialsQuery } from 'data/storage/s3-access-key-query'
+import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
+import {
+ Button,
+ DialogSectionSeparator,
+ FormControl_Shadcn_,
+ FormField_Shadcn_,
+ Input_Shadcn_,
+ Select_Shadcn_,
+ SelectContent_Shadcn_,
+ SelectGroup_Shadcn_,
+ SelectItem_Shadcn_,
+ SelectSeparator_Shadcn_,
+ SelectTrigger_Shadcn_,
+ TextArea_Shadcn_,
+ WarningIcon,
+} from 'ui'
+import { Admonition } from 'ui-patterns'
+import { Input } from 'ui-patterns/DataInputs/Input'
+import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
+import { CREATE_NEW_KEY, CREATE_NEW_NAMESPACE } from './DestinationPanel.constants'
+import { DestinationPanelSchemaType } from './DestinationPanel.schema'
+
+export const BigQueryFields = ({ form }: { form: UseFormReturn<DestinationPanelSchemaType> }) => {
+ return (
+ <>
+ <FormField_Shadcn_
+ control={form.control}
+ name="projectId"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="vertical"
+ className="px-5"
+ label="Project ID"
+ description="Which BigQuery project to send data to"
+ >
+ <FormControl_Shadcn_>
+ <Input_Shadcn_ {...field} placeholder="Project ID" />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+
+ <FormField_Shadcn_
+ control={form.control}
+ name="datasetId"
+ render={({ field }) => (
+ <FormItemLayout label="Project's Dataset ID" layout="vertical" className="px-5">
+ <FormControl_Shadcn_>
+ <Input_Shadcn_ {...field} placeholder="Dataset ID" />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+
+ <FormField_Shadcn_
+ control={form.control}
+ name="serviceAccountKey"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="vertical"
+ className="px-5"
+ label="Service Account Key"
+ description="The service account key for BigQuery"
+ >
+ <FormControl_Shadcn_>
+ <TextArea_Shadcn_
+ {...field}
+ rows={4}
+ maxLength={5000}
+ placeholder="Service account key"
+ />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+ </>
+ )
+}
+
+/**
+ * [Joshen] JFYI I'd foresee a possible UX friction point here regarding S3 access key IDs and secret access keys
+ * - We'd allow users to select access key IDs via a dropdown here, but require a text input for secret access keys
+ * - Chances are most users wouldn't have the corresponding secret access key for the selected key ID at the top of their heads
+ * - So highly likely may have to default to "Create a new key" -> which from here they won't know the secret access key thereafter
+ * - And it'll end up just creating more keys for each destination
+ * Ideal scenario: Just select an access key ID, we then apply the secret access key in the PATCH request, so FE has no
+ * context of the secret access key at any point
+ */
+export const AnalyticsBucketFields = ({
+ form,
+ setIsFormInteracting,
+}: {
+ form: UseFormReturn<DestinationPanelSchemaType>
+ setIsFormInteracting: (value: boolean) => void
+}) => {
+ const { warehouseName, type, s3AccessKeyId, namespace } = form.watch()
+ const [showCatalogToken, setShowCatalogToken] = useState(false)
+ const [showSecretAccessKey, setShowSecretAccessKey] = useState(false)
+
+ const { ref: projectRef } = useParams()
+ const isStorageV2 = useIsNewStorageUIEnabled()
+ const { data: project } = useSelectedProjectQuery()
+
+ const { data: apiKeys } = useAPIKeysQuery({ projectRef, reveal: true })
+ const { serviceKey } = getKeys(apiKeys)
+ const serviceApiKey = serviceKey?.api_key ?? ''
+
+ const { data: projectSettings } = useProjectSettingsV2Query({ projectRef })
+
+ const {
+ data: keysData,
+ isSuccess: isSuccessKeys,
+ isLoading: isLoadingKeys,
+ isError: isErrorKeys,
+ } = useStorageCredentialsQuery({ projectRef })
+ const s3Keys = keysData?.data ?? []
+ const keyNoLongerExists =
+ (s3AccessKeyId ?? '').length > 0 &&
+ s3AccessKeyId !== CREATE_NEW_KEY &&
+ !s3Keys.find((k) => k.access_key === s3AccessKeyId)
+
+ const {
+ data: buckets = [],
+ isLoading: isLoadingBuckets,
+ isError: isErrorBuckets,
+ } = useBucketsQuery({ projectRef })
+ const analyticsBuckets = buckets.filter((bucket) => bucket.type === 'ANALYTICS')
+
+ // Construct catalog URI for iceberg namespaces query
+ const catalogUri = useMemo(() => {
+ if (!project?.ref || !projectSettings) return ''
+ const protocol = projectSettings.app_config?.protocol ?? 'https'
+ const endpoint =
+ projectSettings.app_config?.storage_endpoint || projectSettings.app_config?.endpoint
+ return getCatalogURI(project.ref, protocol, endpoint)
+ }, [project?.ref, projectSettings])
+
+ const canSelectNamespace = !!warehouseName && !!serviceApiKey
+
+ const {
+ data: namespaces = [],
+ isLoading: isLoadingNamespaces,
+ isError: isErrorNamespaces,
+ refetch: refetchNamespaces,
+ } = useIcebergNamespacesQuery(
+ {
+ catalogUri,
+ warehouse: warehouseName || '',
+ token: serviceApiKey || '',
+ },
+ {
+ enabled: type === 'Analytics Bucket' && !!catalogUri && !!warehouseName && !!serviceApiKey,
+ }
+ )
+
+ return (
+ <>
+ <FormField_Shadcn_
+ control={form.control}
+ name="warehouseName"
+ render={({ field }) => (
+ <FormItemLayout
+ label="Bucket"
+ layout="vertical"
+ className="px-5"
+ description="Select a storage Analytics Bucket to use as your warehouse"
+ >
+ {isLoadingBuckets ? (
+ <Button
+ disabled
+ type="default"
+ className="w-full justify-between"
+ size="small"
+ iconRight={<Loader2 className="animate-spin" />}
+ >
+ Retrieving buckets
+ </Button>
+ ) : isErrorBuckets ? (
+ <Button
+ disabled
+ type="default"
+ className="w-full justify-start"
+ size="small"
+ icon={<WarningIcon />}
+ >
+ Failed to retrieve buckets
+ </Button>
+ ) : (
+ <FormControl_Shadcn_>
+ <Select_Shadcn_
+ value={field.value}
+ onValueChange={(value) => {
+ setIsFormInteracting(true)
+ field.onChange(value)
+ // [Joshen] Ideally should select the first namespace of the selected bucket
+ form.setValue('namespace', '')
+ }}
+ >
+ <SelectTrigger_Shadcn_>{field.value || 'Select a bucket'}</SelectTrigger_Shadcn_>
+ <SelectContent_Shadcn_>
+ <SelectGroup_Shadcn_>
+ {analyticsBuckets.length === 0 ? (
+ <SelectItem_Shadcn_ value="__no_buckets__" disabled>
+ No buckets available
+ </SelectItem_Shadcn_>
+ ) : (
+ analyticsBuckets.map((bucket) => (
+ <SelectItem_Shadcn_ key={bucket.id} value={bucket.name}>
+ {bucket.name}
+ </SelectItem_Shadcn_>
+ ))
+ )}
+ </SelectGroup_Shadcn_>
+ </SelectContent_Shadcn_>
+ </Select_Shadcn_>
+ </FormControl_Shadcn_>
+ )}
+ </FormItemLayout>
+ )}
+ />
+
+ <FormField_Shadcn_
+ control={form.control}
+ name="namespace"
+ render={({ field }) => (
+ <FormItemLayout
+ label="Namespace"
+ layout="vertical"
+ className="px-5"
+ description="Select a namespace from your Analytics Bucket"
+ >
+ {isLoadingNamespaces && canSelectNamespace ? (
+ <Button
+ disabled
+ type="default"
+ className="w-full justify-between"
+ size="small"
+ iconRight={<Loader2 className="animate-spin" />}
+ >
+ Retrieving namespaces
+ </Button>
+ ) : isErrorNamespaces ? (
+ <Button
+ disabled
+ type="default"
+ className="w-full justify-start"
+ size="small"
+ icon={<WarningIcon />}
+ >
+ Failed to retrieve namespaces
+ </Button>
+ ) : (
+ <FormControl_Shadcn_>
+ <Select_Shadcn_
+ value={field.value}
+ onValueChange={(value) => {
+ setIsFormInteracting(true)
+ field.onChange(value)
+ }}
+ disabled={!canSelectNamespace}
+ >
+ <SelectTrigger_Shadcn_>
+ {!canSelectNamespace
+ ? 'Select a warehouse first'
+ : field.value === CREATE_NEW_NAMESPACE
+ ? 'Create a new namespace'
+ : field.value || 'Select a namespace'}
+ </SelectTrigger_Shadcn_>
+ <SelectContent_Shadcn_>
+ <SelectGroup_Shadcn_>
+ {namespaces.length === 0 ? (
+ <SelectItem_Shadcn_ value="__no_namespaces__" disabled>
+ No namespaces available
+ </SelectItem_Shadcn_>
+ ) : (
+ namespaces.map((namespace) => (
+ <SelectItem_Shadcn_ key={namespace} value={namespace}>
+ {namespace}
+ </SelectItem_Shadcn_>
+ ))
+ )}
+ {namespaces.length > 0 && <SelectSeparator_Shadcn_ />}
+ <SelectItem_Shadcn_ key={CREATE_NEW_NAMESPACE} value={CREATE_NEW_NAMESPACE}>
+ Create a new namespace
+ </SelectItem_Shadcn_>
+ </SelectGroup_Shadcn_>
+ </SelectContent_Shadcn_>
+ </Select_Shadcn_>
+ </FormControl_Shadcn_>
+ )}
+ </FormItemLayout>
+ )}
+ />
+
+ {namespace === CREATE_NEW_NAMESPACE && (
+ <FormField_Shadcn_
+ control={form.control}
+ name="newNamespaceName"
+ render={({ field }) => (
+ <FormItemLayout
+ label="New Namespace Name"
+ layout="vertical"
+ className="px-5"
+ description="Enter a name for the new namespace"
+ >
+ <FormControl_Shadcn_>
+ <Input_Shadcn_ {...field} placeholder="new_namespace" value={field.value || ''} />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+ )}
+
+ <DialogSectionSeparator />
+
+ <p className="px-5 text-sm text-foreground-light">Credentials</p>
+
+ <FormField_Shadcn_
+ control={form.control}
+ name="catalogToken"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="vertical"
+ label="Catalog Token"
+ className="px-5"
+ description={
+ <>
+ Automatically retrieved from your project's{' '}
+ <InlineLink href={`/project/${projectRef}/settings/api-keys`}>
+ service role key
+ </InlineLink>
+ </>
+ }
+ >
+ <Input
+ disabled
+ value={field.value}
+ type={showCatalogToken ? 'text' : 'password'}
+ placeholder="Auto-populated"
+ actions={
+ serviceApiKey ? (
+ <div className="flex items-center justify-center">
+ <Button
+ type="default"
+ className="w-7"
+ icon={showCatalogToken ? <Eye /> : <EyeOff />}
+ onClick={() => setShowCatalogToken(!showCatalogToken)}
+ />
+ </div>
+ ) : null
+ }
+ />
+ </FormItemLayout>
+ )}
+ />
+
+ <FormField_Shadcn_
+ control={form.control}
+ name="s3AccessKeyId"
+ render={({ field }) => (
+ <FormItemLayout layout="vertical" label="S3 Access Key ID" className="px-5">
+ {isLoadingKeys ? (
+ <Button
+ disabled
+ type="default"
+ className="w-full justify-between"
+ size="small"
+ iconRight={<Loader2 className="animate-spin" />}
+ >
+ Retrieving keys
+ </Button>
+ ) : isErrorKeys ? (
+ <Button
+ disabled
+ type="default"
+ className="w-full justify-start"
+ size="small"
+ icon={<WarningIcon />}
+ >
+ Failed to retrieve keys
+ </Button>
+ ) : (
+ <FormControl_Shadcn_>
+ <Select_Shadcn_ value={field.value} onValueChange={field.onChange}>
+ <SelectTrigger_Shadcn_>
+ {field.value === CREATE_NEW_KEY
+ ? 'Create a new key'
+ : (field.value ?? '').length === 0
+ ? 'Select an access key ID'
+ : field.value}
+ </SelectTrigger_Shadcn_>
+ <SelectContent_Shadcn_>
+ <SelectGroup_Shadcn_>
+ {s3Keys.map((key) => (
+ <SelectItem_Shadcn_ key={key.id} value={key.access_key}>
+ {key.access_key}
+ <p className="text-foreground-lighter">{key.description}</p>
+ </SelectItem_Shadcn_>
+ ))}
+ <SelectSeparator_Shadcn_ />
+ <SelectItem_Shadcn_ key={CREATE_NEW_KEY} value={CREATE_NEW_KEY}>
+ Create a new key
+ </SelectItem_Shadcn_>
+ </SelectGroup_Shadcn_>
+ </SelectContent_Shadcn_>
+ </Select_Shadcn_>
+ </FormControl_Shadcn_>
+ )}
+ </FormItemLayout>
+ )}
+ />
+
+ {isSuccessKeys && keyNoLongerExists && (
+ <div className="px-5">
+ <Admonition type="warning" title="Unable to find access key ID in project">
+ <p className="!leading-normal">
+ Please select another key or create a new set, as this destination will not work
+ otherwise. S3 access keys can be managed in your{' '}
+ <InlineLink
+ href={
+ isStorageV2
+ ? `/project/${projectRef}/storage/files/settings`
+ : `/project/${projectRef}/storage/settings`
+ }
+ >
+ storage settings
+ </InlineLink>
+ </p>
+ </Admonition>
+ </div>
+ )}
+
+ {s3AccessKeyId === CREATE_NEW_KEY ? (
+ <div className="px-5">
+ <Admonition type="default" title="A new set of S3 access keys will be created">
+ <p className="!leading-normal">
+ S3 access keys can be managed in your{' '}
+ <InlineLink
+ href={
+ isStorageV2
+ ? `/project/${projectRef}/storage/files/settings`
+ : `/project/${projectRef}/storage/settings`
+ }
+ >
+ storage settings
+ </InlineLink>
+ .
+ </p>
+ </Admonition>
+ </div>
+ ) : (
+ <FormField_Shadcn_
+ control={form.control}
+ name="s3SecretAccessKey"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="vertical"
+ label="S3 Secret Access Key"
+ className="relative px-5"
+ description="The corresponding secret access key for the selected key ID"
+ >
+ <FormControl_Shadcn_>
+ <Input_Shadcn_
+ {...field}
+ type={showSecretAccessKey ? 'text' : 'password'}
+ value={field.value ?? ''}
+ />
+ </FormControl_Shadcn_>
+ <Button
+ type="default"
+ icon={showSecretAccessKey ? <Eye /> : <EyeOff />}
+ className="w-7 absolute right-6 top-[33px]"
+ onClick={() => setShowSecretAccessKey(!showSecretAccessKey)}
+ />
+ </FormItemLayout>
+ )}
+ />
+ )}
+ </>
+ )
+}
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationRow.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationRow.tsx
index 05e57b5345b..557c26f7f37 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationRow.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationRow.tsx
@@ -1,3 +1,4 @@
+import { AlertCircle } from 'lucide-react'
import Link from 'next/link'
import { useEffect, useState } from 'react'
import { toast } from 'sonner'
@@ -11,7 +12,6 @@ import { useReplicationPipelineStatusQuery } from 'data/replication/pipeline-sta
import { useReplicationPipelineVersionQuery } from 'data/replication/pipeline-version-query'
import { Pipeline } from 'data/replication/pipelines-query'
import { useStopPipelineMutation } from 'data/replication/stop-pipeline-mutation'
-import { AlertCircle } from 'lucide-react'
import {
PipelineStatusRequestStatus,
usePipelineRequestStatus,
@@ -20,7 +20,8 @@ import { ResponseError } from 'types'
import { Button, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
import ShimmeringLoader from 'ui-patterns/ShimmeringLoader'
import { DeleteDestination } from './DeleteDestination'
-import { DestinationPanel } from './DestinationPanel'
+import { DestinationPanel } from './DestinationPanel/DestinationPanel'
+import { DestinationPanelSchemaType } from './DestinationPanel/DestinationPanel.schema'
import { getStatusName, PIPELINE_ERROR_MESSAGES } from './Pipeline.utils'
import { PipelineStatus } from './PipelineStatus'
import { PipelineStatusName, STATUS_REFRESH_FREQUENCY_MS } from './Replication.constants'
@@ -31,7 +32,7 @@ interface DestinationRowProps {
sourceId?: number
destinationId: number
destinationName: string
- type: string
+ type: DestinationPanelSchemaType['type'] | 'Other'
pipeline?: Pipeline
error: ResponseError | null
isLoading: boolean
diff --git a/apps/studio/components/interfaces/Database/Replication/Destinations.tsx b/apps/studio/components/interfaces/Database/Replication/Destinations.tsx
index 7cef5dd364b..fe695472be3 100644
--- a/apps/studio/components/interfaces/Database/Replication/Destinations.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/Destinations.tsx
@@ -14,7 +14,7 @@ import { useReplicationSourcesQuery } from 'data/replication/sources-query'
import { DOCS_URL } from 'lib/constants'
import { Button, cn, Input_Shadcn_ } from 'ui'
import { GenericSkeletonLoader } from 'ui-patterns'
-import { DestinationPanel } from './DestinationPanel'
+import { DestinationPanel } from './DestinationPanel/DestinationPanel'
import { DestinationRow } from './DestinationRow'
import { EnableReplicationModal } from './EnableReplicationModal'
import { PIPELINE_ERROR_MESSAGES } from './Pipeline.utils'
@@ -153,13 +153,21 @@ export const Destinations = () => {
const pipeline = pipelinesData?.pipelines.find(
(p) => p.destination_id === destination.id
)
+
+ const type =
+ 'big_query' in destination.config
+ ? 'BigQuery'
+ : 'iceberg' in destination.config
+ ? 'Analytics Bucket'
+ : 'Other'
+
return (
<DestinationRow
key={destination.id}
sourceId={sourceId}
destinationId={destination.id}
destinationName={destination.name}
- type={'big_query' in destination.config ? 'BigQuery' : 'Other'}
+ type={type}
pipeline={pipeline}
error={pipelinesError}
isLoading={isPipelinesLoading}
diff --git a/apps/studio/components/interfaces/Database/Replication/NewPublicationPanel.tsx b/apps/studio/components/interfaces/Database/Replication/NewPublicationPanel.tsx
index 384cdf61906..e062afeb6b8 100644
--- a/apps/studio/components/interfaces/Database/Replication/NewPublicationPanel.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/NewPublicationPanel.tsx
@@ -6,23 +6,23 @@ import { X } from 'lucide-react'
import { useForm } from 'react-hook-form'
import { toast } from 'sonner'
import {
- Sheet,
- SheetContent,
- SheetHeader,
- SheetTitle,
- SheetClose,
- cn,
Button,
- SheetFooter,
- SheetSection,
+ cn,
Form_Shadcn_,
- FormField_Shadcn_,
FormControl_Shadcn_,
+ FormField_Shadcn_,
Input_Shadcn_,
+ Sheet,
+ SheetClose,
+ SheetContent,
SheetDescription,
+ SheetFooter,
+ SheetHeader,
+ SheetSection,
+ SheetTitle,
} from 'ui'
-import { MultiSelector } from 'ui-patterns/multi-select'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
+import { MultiSelector } from 'ui-patterns/multi-select'
import { z } from 'zod'
interface NewPublicationPanelProps {
@@ -31,7 +31,7 @@ interface NewPublicationPanelProps {
onClose: () => void
}
-const NewPublicationPanel = ({ visible, sourceId, onClose }: NewPublicationPanelProps) => {
+export const NewPublicationPanel = ({ visible, sourceId, onClose }: NewPublicationPanelProps) => {
const { ref: projectRef } = useParams()
const { mutateAsync: createPublication, isLoading: creatingPublication } =
useCreatePublicationMutation()
@@ -170,5 +170,3 @@ const NewPublicationPanel = ({ visible, sourceId, onClose }: NewPublicationPanel
</>
)
}
-
-export default NewPublicationPanel
diff --git a/apps/studio/components/interfaces/Database/Replication/PublicationsComboBox.tsx b/apps/studio/components/interfaces/Database/Replication/PublicationsComboBox.tsx
index 268edf139cd..c0927679aa6 100644
--- a/apps/studio/components/interfaces/Database/Replication/PublicationsComboBox.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/PublicationsComboBox.tsx
@@ -25,7 +25,7 @@ interface PublicationsComboBoxProps {
field: ControllerRenderProps<any, 'publicationName'>
}
-const PublicationsComboBox = ({
+export const PublicationsComboBox = ({
publications,
isLoadingPublications,
isLoadingCheck,
@@ -138,5 +138,3 @@ const PublicationsComboBox = ({
</Popover_Shadcn_>
)
}
-
-export default PublicationsComboBox
diff --git a/apps/studio/components/interfaces/HomeNew/Home.tsx b/apps/studio/components/interfaces/HomeNew/Home.tsx
index 9e5632507ed..820fb1728ae 100644
--- a/apps/studio/components/interfaces/HomeNew/Home.tsx
+++ b/apps/studio/components/interfaces/HomeNew/Home.tsx
@@ -85,7 +85,6 @@ export const HomeV2 = () => {
<TopSection />
</ScaffoldSection>
</ScaffoldContainer>
-
{!isPaused && (
<ScaffoldContainer size="large">
<ScaffoldSection isFullWidth className="gap-16 pb-32">
diff --git a/apps/studio/data/replication/create-destination-pipeline-mutation.ts b/apps/studio/data/replication/create-destination-pipeline-mutation.ts
index 2189dd8cd06..456dc678846 100644
--- a/apps/studio/data/replication/create-destination-pipeline-mutation.ts
+++ b/apps/studio/data/replication/create-destination-pipeline-mutation.ts
@@ -1,6 +1,7 @@
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
import { toast } from 'sonner'
+import type { components } from 'api-types'
import { handleError, post } from 'data/fetchers'
import type { ResponseError } from 'types'
import { replicationKeys } from './keys'
@@ -12,12 +13,26 @@ export type BigQueryDestinationConfig = {
maxStalenessMins?: number
}
+export type IcebergDestinationConfig = {
+ projectRef: string
+ warehouseName: string
+ namespace: string
+ catalogToken: string
+ s3AccessKeyId: string
+ s3SecretAccessKey: string
+ s3Region: string
+}
+
export type CreateDestinationPipelineParams = {
projectRef: string
destinationName: string
- destinationConfig: {
- bigQuery: BigQueryDestinationConfig
- }
+ destinationConfig:
+ | {
+ bigQuery: BigQueryDestinationConfig
+ }
+ | {
+ iceberg: IcebergDestinationConfig
+ }
sourceId: number
pipelineConfig: {
publicationName: string
@@ -31,9 +46,7 @@ async function createDestinationPipeline(
{
projectRef,
destinationName: destinationName,
- destinationConfig: {
- bigQuery: { projectId, datasetId, serviceAccountKey, maxStalenessMins },
- },
+ destinationConfig,
pipelineConfig: { publicationName, batch },
sourceId,
}: CreateDestinationPipelineParams,
@@ -41,28 +54,55 @@ async function createDestinationPipeline(
) {
if (!projectRef) throw new Error('projectRef is required')
+ // Build destination_config based on the type
+ let destination_config: components['schemas']['CreateReplicationDestinationPipelineBody']['destination_config']
+
+ if ('bigQuery' in destinationConfig) {
+ const { projectId, datasetId, serviceAccountKey, maxStalenessMins } = destinationConfig.bigQuery
+ destination_config = {
+ big_query: {
+ project_id: projectId,
+ dataset_id: datasetId,
+ service_account_key: serviceAccountKey,
+ ...(maxStalenessMins !== null ? { max_staleness_mins: maxStalenessMins } : {}),
+ },
+ }
+ } else if ('iceberg' in destinationConfig) {
+ const {
+ projectRef: icebergProjectRef,
+ warehouseName,
+ namespace,
+ catalogToken,
+ s3AccessKeyId,
+ s3SecretAccessKey,
+ s3Region,
+ } = destinationConfig.iceberg
+ destination_config = {
+ iceberg: {
+ supabase: {
+ project_ref: icebergProjectRef,
+ warehouse_name: warehouseName,
+ namespace: namespace,
+ catalog_token: catalogToken,
+ s3_access_key_id: s3AccessKeyId,
+ s3_secret_access_key: s3SecretAccessKey,
+ s3_region: s3Region,
+ },
+ },
+ }
+ } else {
+ throw new Error('Invalid destination config: must specify either bigQuery or iceberg')
+ }
+
const { data, error } = await post('/platform/replication/{ref}/destinations-pipelines', {
params: { path: { ref: projectRef } },
body: {
source_id: sourceId,
destination_name: destinationName,
- destination_config: {
- big_query: {
- project_id: projectId,
- dataset_id: datasetId,
- service_account_key: serviceAccountKey,
- ...(maxStalenessMins != null && { max_staleness_mins: maxStalenessMins }),
- },
- },
+ destination_config,
pipeline_config: {
publication_name: publicationName,
- ...(batch
- ? {
- batch: {
- max_fill_ms: batch.maxFillMs,
- },
- }
- : {}),
+ ...(!!batch ? { batch: { max_fill_ms: batch.maxFillMs } } : {}),
},
},
signal,
diff --git a/apps/studio/data/replication/destination-by-id-query.ts b/apps/studio/data/replication/destination-by-id-query.ts
index 9d7559bf831..c595a3e1fd2 100644
--- a/apps/studio/data/replication/destination-by-id-query.ts
+++ b/apps/studio/data/replication/destination-by-id-query.ts
@@ -2,6 +2,7 @@ import { UseQueryOptions, useQuery } from '@tanstack/react-query'
import { get, handleError } from 'data/fetchers'
import { ResponseError } from 'types'
+import type { components } from 'api-types'
import { replicationKeys } from './keys'
type ReplicationDestinationByIdParams = { projectRef?: string; destinationId?: number }
@@ -23,9 +24,7 @@ async function fetchReplicationDestinationById(
return data
}
-export type ReplicationDestinationByIdData = Awaited<
- ReturnType<typeof fetchReplicationDestinationById>
->
+export type ReplicationDestinationByIdData = components['schemas']['ReplicationDestinationResponse']
export const useReplicationDestinationByIdQuery = <TData = ReplicationDestinationByIdData>(
{ projectRef, destinationId }: ReplicationDestinationByIdParams,
diff --git a/apps/studio/data/replication/pipeline-by-id-query.ts b/apps/studio/data/replication/pipeline-by-id-query.ts
index 6482dc49c82..91d710ef4f7 100644
--- a/apps/studio/data/replication/pipeline-by-id-query.ts
+++ b/apps/studio/data/replication/pipeline-by-id-query.ts
@@ -2,6 +2,7 @@ import { UseQueryOptions, useQuery } from '@tanstack/react-query'
import { get, handleError } from 'data/fetchers'
import { ResponseError } from 'types'
+import type { components } from 'api-types'
import { replicationKeys } from './keys'
type ReplicationPipelineByIdParams = { projectRef?: string; pipelineId?: number }
@@ -23,7 +24,7 @@ async function fetchReplicationPipelineById(
return data
}
-export type ReplicationPipelineByIdData = Awaited<ReturnType<typeof fetchReplicationPipelineById>>
+export type ReplicationPipelineByIdData = components['schemas']['ReplicationPipelineResponse']
export const useReplicationPipelineByIdQuery = <TData = ReplicationPipelineByIdData>(
{ projectRef, pipelineId }: ReplicationPipelineByIdParams,
diff --git a/apps/studio/data/replication/update-destination-pipeline-mutation.ts b/apps/studio/data/replication/update-destination-pipeline-mutation.ts
index 2bd6830a8e5..04d37d9f670 100644
--- a/apps/studio/data/replication/update-destination-pipeline-mutation.ts
+++ b/apps/studio/data/replication/update-destination-pipeline-mutation.ts
@@ -1,6 +1,7 @@
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
import { toast } from 'sonner'
+import type { components } from 'api-types'
import { handleError, post } from 'data/fetchers'
import type { ResponseError } from 'types'
import { replicationKeys } from './keys'
@@ -12,14 +13,28 @@ export type BigQueryDestinationConfig = {
maxStalenessMins?: number
}
+export type IcebergDestinationConfig = {
+ projectRef: string
+ warehouseName: string
+ namespace: string
+ catalogToken: string
+ s3AccessKeyId: string
+ s3SecretAccessKey: string
+ s3Region: string
+}
+
export type UpdateDestinationPipelineParams = {
destinationId: number
pipelineId: number
projectRef: string
destinationName: string
- destinationConfig: {
- bigQuery: BigQueryDestinationConfig
- }
+ destinationConfig:
+ | {
+ bigQuery: BigQueryDestinationConfig
+ }
+ | {
+ iceberg: IcebergDestinationConfig
+ }
sourceId: number
pipelineConfig: {
publicationName: string
@@ -35,9 +50,7 @@ async function updateDestinationPipeline(
pipelineId,
projectRef,
destinationName: destinationName,
- destinationConfig: {
- bigQuery: { projectId, datasetId, serviceAccountKey, maxStalenessMins },
- },
+ destinationConfig,
pipelineConfig: { publicationName, batch },
sourceId,
}: UpdateDestinationPipelineParams,
@@ -45,37 +58,63 @@ async function updateDestinationPipeline(
) {
if (!projectRef) throw new Error('projectRef is required')
+ // Build destination_config based on the type
+ let destination_config: components['schemas']['UpdateReplicationDestinationPipelineBody']['destination_config']
+
+ if ('bigQuery' in destinationConfig) {
+ const { projectId, datasetId, serviceAccountKey, maxStalenessMins } = destinationConfig.bigQuery
+ destination_config = {
+ big_query: {
+ project_id: projectId,
+ dataset_id: datasetId,
+ service_account_key: serviceAccountKey,
+ ...(maxStalenessMins !== null ? { max_staleness_mins: maxStalenessMins } : {}),
+ },
+ }
+ } else if ('iceberg' in destinationConfig) {
+ const {
+ projectRef: icebergProjectRef,
+ warehouseName,
+ namespace,
+ catalogToken,
+ s3AccessKeyId,
+ s3SecretAccessKey,
+ s3Region,
+ } = destinationConfig.iceberg
+ destination_config = {
+ iceberg: {
+ supabase: {
+ project_ref: icebergProjectRef,
+ warehouse_name: warehouseName,
+ namespace: namespace,
+ catalog_token: catalogToken,
+ s3_access_key_id: s3AccessKeyId,
+ s3_secret_access_key: s3SecretAccessKey,
+ s3_region: s3Region,
+ },
+ },
+ }
+ } else {
+ throw new Error('Invalid destination config: must specify either bigQuery or iceberg')
+ }
+
const { data, error } = await post(
'/platform/replication/{ref}/destinations-pipelines/{destination_id}/{pipeline_id}',
{
params: { path: { ref: projectRef, destination_id: destinationId, pipeline_id: pipelineId } },
body: {
+ destination_config,
+ source_id: sourceId,
destination_name: destinationName,
- destination_config: {
- big_query: {
- project_id: projectId,
- dataset_id: datasetId,
- service_account_key: serviceAccountKey,
- ...(maxStalenessMins != null && { max_staleness_mins: maxStalenessMins }),
- },
- },
pipeline_config: {
publication_name: publicationName,
- ...(batch && {
- batch: {
- max_fill_ms: batch.maxFillMs,
- },
- }),
+ ...(!!batch ? { batch: { max_fill_ms: batch.maxFillMs } } : {}),
},
- source_id: sourceId,
},
signal,
}
)
- if (error) {
- handleError(error)
- }
-
+ if (error) handleError(error)
return data
}
diff --git a/apps/studio/data/storage/iceberg-namespace-create-mutation.ts b/apps/studio/data/storage/iceberg-namespace-create-mutation.ts
index a2f68b752db..53ecb594443 100644
--- a/apps/studio/data/storage/iceberg-namespace-create-mutation.ts
+++ b/apps/studio/data/storage/iceberg-namespace-create-mutation.ts
@@ -12,6 +12,7 @@ type CreateIcebergNamespaceVariables = {
namespace: string
}
+// [Joshen] Investigate if we can use the temp API keys here
async function createIcebergNamespace({
catalogUri,
warehouse,
@@ -80,6 +81,9 @@ export const useIcebergNamespaceCreateMutation = ({
variables.namespace
)
)
+ await queryClient.invalidateQueries(
+ storageKeys.icebergNamespaces(variables.catalogUri, variables.warehouse)
+ )
await onSuccess?.(data, variables, context)
},
async onError(data, variables, context) {
diff --git a/apps/studio/data/storage/iceberg-namespaces-query.ts b/apps/studio/data/storage/iceberg-namespaces-query.ts
index bace45078f4..6671670a858 100644
--- a/apps/studio/data/storage/iceberg-namespaces-query.ts
+++ b/apps/studio/data/storage/iceberg-namespaces-query.ts
@@ -10,6 +10,7 @@ type GetNamespacesVariables = {
token: string
}
+// [Joshen] Investigate if we can use the temp API keys here
async function getNamespaces({ catalogUri, warehouse, token }: GetNamespacesVariables) {
let headers = new Headers()
// handle both secret key and service role key