Skip to content

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

feat(replication): Delete destination and pipeline atomically (#37790)

Riccardo Busettie9424b98deec
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationRow.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationRow.tsx
index 5e693553554..85d315f7ef7 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationRow.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationRow.tsx
@@ -5,7 +5,7 @@ import { toast } from 'sonner'
import { useParams } from 'common'
import Table from 'components/to-be-cleaned/Table'
import AlertError from 'components/ui/AlertError'
-import { useDeleteDestinationMutation } from 'data/replication/delete-destination-mutation'
+import { useDeleteDestinationPipelineMutation } from 'data/replication/delete-destination-pipeline-mutation'
import { useReplicationPipelineStatusQuery } from 'data/replication/pipeline-status-query'
import { Pipeline } from 'data/replication/pipelines-query'
import { useStopPipelineMutation } from 'data/replication/stop-pipeline-mutation'
@@ -69,7 +69,7 @@ export const DestinationRow = ({
: PipelineStatusRequestStatus.None
const { mutateAsync: stopPipeline } = useStopPipelineMutation()
- const { mutateAsync: deleteDestination } = useDeleteDestinationMutation({})
+ const { mutateAsync: deleteDestinationPipeline } = useDeleteDestinationPipelineMutation({})
const pipelineStatus = pipelineStatusData?.status
const statusName = getStatusName(pipelineStatus)
@@ -84,9 +84,11 @@ export const DestinationRow = ({
try {
await stopPipeline({ projectRef, pipelineId: pipeline.id })
- // deleting the destination also deletes the pipeline because of cascade delete
- // so we don't need to call deletePipeline explicitly
- await deleteDestination({ projectRef, destinationId: destinationId })
+ await deleteDestinationPipeline({
+ projectRef,
+ destinationId: destinationId,
+ pipelineId: pipeline.id,
+ })
} catch (error) {
toast.error(PIPELINE_ERROR_MESSAGES.DELETE_DESTINATION)
}
diff --git a/apps/studio/data/replication/delete-destination-mutation.ts b/apps/studio/data/replication/delete-destination-mutation.ts
deleted file mode 100644
index ce17893e5c4..00000000000
--- a/apps/studio/data/replication/delete-destination-mutation.ts
+++ /dev/null
@@ -1,60 +0,0 @@
-import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
-import { toast } from 'sonner'
-
-import type { ResponseError } from 'types'
-import { replicationKeys } from './keys'
-import { handleError, del } from 'data/fetchers'
-
-export type DeleteDestinationParams = {
- projectRef: string
- destinationId: number
-}
-
-async function deleteDestination(
- { projectRef, destinationId: destinationId }: DeleteDestinationParams,
- signal?: AbortSignal
-) {
- if (!projectRef) throw new Error('projectRef is required')
-
- const { data, error } = await del('/platform/replication/{ref}/destinations/{destination_id}', {
- params: { path: { ref: projectRef, destination_id: destinationId } },
- signal,
- })
- if (error) {
- handleError(error)
- }
-
- return data
-}
-
-type DeleteDestinationData = Awaited<ReturnType<typeof deleteDestination>>
-
-export const useDeleteDestinationMutation = ({
- onSuccess,
- onError,
- ...options
-}: Omit<
- UseMutationOptions<DeleteDestinationData, ResponseError, DeleteDestinationParams>,
- 'mutationFn'
-> = {}) => {
- const queryClient = useQueryClient()
-
- return useMutation<DeleteDestinationData, ResponseError, DeleteDestinationParams>(
- (vars) => deleteDestination(vars),
- {
- async onSuccess(data, variables, context) {
- const { projectRef, destinationId } = variables
- await queryClient.invalidateQueries(replicationKeys.destinations(projectRef))
- await onSuccess?.(data, variables, context)
- },
- async onError(data, variables, context) {
- if (onError === undefined) {
- toast.error(`Failed to delete destination: ${data.message}`)
- } else {
- onError(data, variables, context)
- }
- },
- ...options,
- }
- )
-}
diff --git a/apps/studio/data/replication/delete-destination-pipeline-mutation.ts b/apps/studio/data/replication/delete-destination-pipeline-mutation.ts
new file mode 100644
index 00000000000..2ccb2473423
--- /dev/null
+++ b/apps/studio/data/replication/delete-destination-pipeline-mutation.ts
@@ -0,0 +1,64 @@
+import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
+import { toast } from 'sonner'
+
+import type { ResponseError } from 'types'
+import { replicationKeys } from './keys'
+import { handleError, del } from 'data/fetchers'
+
+export type DeleteDestinationPipelineParams = {
+ projectRef: string
+ destinationId: number
+ pipelineId: number
+}
+
+async function deleteDestinationPipeline(
+ { projectRef, destinationId, pipelineId }: DeleteDestinationPipelineParams,
+ signal?: AbortSignal
+) {
+ if (!projectRef) throw new Error('projectRef is required')
+
+ const { data, error } = await del(
+ '/platform/replication/{ref}/destinations-pipelines/{destination_id}/{pipeline_id}',
+ {
+ params: { path: { ref: projectRef, destination_id: destinationId, pipeline_id: pipelineId } },
+ signal,
+ }
+ )
+ if (error) {
+ handleError(error)
+ }
+
+ return data
+}
+
+type DeleteDestinationPipelineData = Awaited<ReturnType<typeof deleteDestinationPipeline>>
+
+export const useDeleteDestinationPipelineMutation = ({
+ onSuccess,
+ onError,
+ ...options
+}: Omit<
+ UseMutationOptions<DeleteDestinationPipelineData, ResponseError, DeleteDestinationPipelineParams>,
+ 'mutationFn'
+> = {}) => {
+ const queryClient = useQueryClient()
+
+ return useMutation<DeleteDestinationPipelineData, ResponseError, DeleteDestinationPipelineParams>(
+ (vars) => deleteDestinationPipeline(vars),
+ {
+ async onSuccess(data, variables, context) {
+ const { projectRef } = variables
+ await queryClient.invalidateQueries(replicationKeys.destinations(projectRef))
+ await onSuccess?.(data, variables, context)
+ },
+ async onError(data, variables, context) {
+ if (onError === undefined) {
+ toast.error(`Failed to delete destination and pipeline: ${data.message}`)
+ } else {
+ onError(data, variables, context)
+ }
+ },
+ ...options,
+ }
+ )
+}
diff --git a/packages/api-types/types/platform.d.ts b/packages/api-types/types/platform.d.ts
index 0e606ba3d32..b84082af171 100644
--- a/packages/api-types/types/platform.d.ts
+++ b/packages/api-types/types/platform.d.ts
@@ -3434,7 +3434,8 @@ export interface paths {
put?: never
/** Update a replication destination and pipeline. */
post: operations['ReplicationDestinationsPipelinesController_updateDestinationPipeline']
- delete?: never
+ /** Delete a replication destination and pipeline. */
+ delete: operations['ReplicationDestinationsPipelinesController_deleteDestinationPipeline']
options?: never
head?: never
patch?: never
@@ -4808,6 +4809,8 @@ export interface components {
}
| {
billing_email: string | null
+ /** @enum {string|null} */
+ billing_partner: 'fly' | 'aws' | 'vercel_marketplace' | null
id: number
is_owner: boolean
name: string
@@ -6582,6 +6585,8 @@ export interface components {
}
OrganizationResponse: {
billing_email: string | null
+ /** @enum {string|null} */
+ billing_partner: 'fly' | 'aws' | 'vercel_marketplace' | null
id: number
is_owner: boolean
name: string
@@ -6634,9 +6639,8 @@ export interface components {
}
OrganizationSlugResponse: {
billing_email: string | null
- billing_metadata: {
- [key: string]: unknown
- } | null
+ /** @enum {string|null} */
+ billing_partner: 'fly' | 'aws' | 'vercel_marketplace' | null
has_oriole_project: boolean
id: number
name: string
@@ -19126,6 +19130,44 @@ export interface operations {
}
}
}
+ ReplicationDestinationsPipelinesController_deleteDestinationPipeline: {
+ parameters: {
+ query?: never
+ header?: never
+ path: {
+ /** @description Destination id */
+ destination_id: number
+ /** @description Pipeline id */
+ pipeline_id: number
+ /** @description Project reference */
+ ref: string
+ }
+ cookie?: never
+ }
+ requestBody?: never
+ responses: {
+ /** @description Returned when the replication destination and pipeline are deleted. */
+ 201: {
+ headers: {
+ [name: string]: unknown
+ }
+ content?: never
+ }
+ 403: {
+ headers: {
+ [name: string]: unknown
+ }
+ content?: never
+ }
+ /** @description Returned when the API fails to delete the replication destination or pipeline. */
+ 500: {
+ headers: {
+ [name: string]: unknown
+ }
+ content?: never
+ }
+ }
+ }
ReplicationDestinationsController_getDestination: {
parameters: {
query?: never