import { useParams } from 'common' import { toast } from 'sonner' import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from 'ui' import { PipelineStatusName } from './Replication.constants' import { RestartCostEstimate } from './RestartCostEstimate' import { shouldCopyTable, type ReplicationTableIdentity, type TableSyncCopyConfig, } from './TableSyncCopy.utils' import { useRollbackTablesMutation } from '@/data/replication/rollback-tables-mutation' interface RestartTableDialogProps { open: boolean onOpenChange: (open: boolean) => void table: ReplicationTableIdentity tableSyncCopy?: TableSyncCopyConfig sourceId?: number publicationName?: string pipelineStatusName?: PipelineStatusName onRestartStart?: () => void onRestartComplete?: () => void } export const RestartTableDialog = ({ open, onOpenChange, table, tableSyncCopy, sourceId, publicationName, pipelineStatusName, onRestartStart, onRestartComplete, }: RestartTableDialogProps) => { const { ref: projectRef, pipelineId: _pipelineId } = useParams() const pipelineId = Number(_pipelineId) const tableName = `${table.schema}.${table.name}` const willCopyTable = shouldCopyTable(tableSyncCopy, table.id) const { mutate: rollbackTables, isPending: isResetting } = useRollbackTablesMutation({ onSuccess: () => { toast.success( `Restarting replication for "${tableName}". Pipeline will ${pipelineStatusName === PipelineStatusName.STOPPED ? 'start' : 'restart'} automatically.` ) }, onSettled: () => { onRestartComplete?.() onOpenChange(false) }, onError: (error) => { toast.error(`Failed to restart replication: ${error.message}`) }, }) const handleReset = () => { if (!projectRef) return toast.error('Project ref is required') if (!pipelineId) return toast.error('Pipeline ID is required') onRestartStart?.() rollbackTables({ projectRef, pipelineId, target: { type: 'single_table', table_id: table.id }, rollbackType: 'full', pipelineStatusName, }) } return ( Restart replication for {tableName}

This will restart replication for{' '} {tableName} from scratch:

    {willCopyTable ? (
  • The table's initial sync will restart. Existing source rows will be synced again. Data successfully processed during this initial sync is billed again.
  • ) : (
  • The table will skip initial sync. Replication will resume with new changes only, without syncing existing source rows. There is no additional initial sync charge.
  • )}
  • Existing downstream data will be deleted. Any replicated data for this table will be removed.
  • All other tables remain untouched. Only this table is affected.
  • The pipeline will restart automatically. This is required to apply this change.
Cancel {isResetting ? 'Restarting replication...' : 'Restart replication'}
) }