Skip to content

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

ref(etl): Improve UX around table resets (#44843)

Riccardo Busettia23e67399342
diff --git a/apps/studio/components/interfaces/Database/Replication/BatchRestartDialog.tsx b/apps/studio/components/interfaces/Database/Replication/BatchRestartDialog.tsx
index ffc6cae2cba..28f2a25f1c5 100644
--- a/apps/studio/components/interfaces/Database/Replication/BatchRestartDialog.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/BatchRestartDialog.tsx
@@ -12,6 +12,7 @@ import {
AlertDialogTitle,
} from 'ui'
+import { PipelineStatusName } from './Replication.constants'
import { ReplicationPipelineTableStatus } from '@/data/replication/pipeline-replication-status-query'
import { useRollbackTablesMutation } from '@/data/replication/rollback-tables-mutation'
@@ -22,6 +23,7 @@ interface BatchRestartDialogProps {
totalTables: number
erroredTablesCount: number
tables: ReplicationPipelineTableStatus[]
+ pipelineStatusName?: PipelineStatusName
onRestartStart?: (tableIds: number[]) => void
onRestartComplete?: (tableIds: number[]) => void
}
@@ -33,12 +35,12 @@ export const BatchRestartDialog = ({
totalTables,
erroredTablesCount,
tables,
+ pipelineStatusName,
onRestartStart,
onRestartComplete,
}: BatchRestartDialogProps) => {
const { ref: projectRef, pipelineId: _pipelineId } = useParams()
const pipelineId = Number(_pipelineId)
-
// Calculate which table IDs will be restarted based on mode (memoized)
const affectedTableIds = useMemo(() => {
if (mode === 'all') {
@@ -61,13 +63,13 @@ export const BatchRestartDialog = ({
toast.success(
`Restarting replication for ${count} table${count > 1 ? 's' : ''}. Pipeline will restart automatically.`
)
+ },
+ onSettled: () => {
onRestartComplete?.(affectedTableIds)
onOpenChange(false)
},
onError: (error) => {
toast.error(`Failed to restart replication: ${error.message}`)
- onRestartComplete?.(affectedTableIds)
- onOpenChange(false)
},
})
@@ -81,6 +83,7 @@ export const BatchRestartDialog = ({
pipelineId,
target: mode === 'all' ? { type: 'all_tables' } : { type: 'all_errored_tables' },
rollbackType: 'full',
+ pipelineStatusName,
})
}
@@ -91,7 +94,8 @@ export const BatchRestartDialog = ({
description: (
<div className="space-y-3 text-sm">
<p>
- This will restart replication for <strong>all {totalTables} tables</strong> in this
+ This will restart replication for all
+ {totalTables === 0 ? '' : totalTables} table{totalTables > 1 ? 's' : ''} in this
pipeline from scratch:
</p>
<ul className="list-disc list-inside space-y-1.5 pl-2">
diff --git a/apps/studio/components/interfaces/Database/Replication/Pipeline.utils.ts b/apps/studio/components/interfaces/Database/Replication/Pipeline.utils.ts
index 6ea1b884fa1..387e6a88509 100644
--- a/apps/studio/components/interfaces/Database/Replication/Pipeline.utils.ts
+++ b/apps/studio/components/interfaces/Database/Replication/Pipeline.utils.ts
@@ -1,8 +1,5 @@
import { PipelineStatusName } from './Replication.constants'
-import {
- ReplicationPipelineStatus,
- ReplicationPipelineStatusData,
-} from '@/data/replication/pipeline-status-query'
+import { ReplicationPipelineStatusData } from '@/data/replication/pipeline-status-query'
import { PipelineStatusRequestStatus } from '@/state/replication-pipeline-request-status'
export const PIPELINE_ERROR_MESSAGES = {
@@ -19,100 +16,134 @@ export const PIPELINE_ERROR_MESSAGES = {
export const getStatusName = (
status: ReplicationPipelineStatusData['status'] | undefined
-): ReplicationPipelineStatusData['status']['name'] | undefined => {
- if (status && typeof status === 'object' && 'name' in status) {
- return status.name
- }
- return undefined
+): PipelineStatusName | undefined => {
+ if (!status || typeof status !== 'object' || !('name' in status)) return undefined
+ return normalizePipelineStatusName(status.name)
}
-export const PIPELINE_ENABLE_ALLOWED_FROM = ['stopped'] as const
-export const PIPELINE_DISABLE_ALLOWED_FROM = ['started', 'failed'] as const
-export const PIPELINE_ACTIONABLE_STATES = ['failed', 'started', 'stopped'] as PipelineStatusName[]
+export const normalizePipelineStatusName = (statusName?: string): PipelineStatusName | undefined =>
+ typeof statusName === 'string' &&
+ (Object.values(PipelineStatusName) as string[]).includes(statusName)
+ ? (statusName as PipelineStatusName)
+ : undefined
+
+export const PIPELINE_ENABLE_ALLOWED_FROM: PipelineStatusName[] = [PipelineStatusName.STOPPED]
+export const PIPELINE_DISABLE_ALLOWED_FROM: PipelineStatusName[] = [
+ PipelineStatusName.STARTED,
+ PipelineStatusName.FAILED,
+]
+export const PIPELINE_ACTIONABLE_STATES: PipelineStatusName[] = [
+ PipelineStatusName.FAILED,
+ PipelineStatusName.STARTED,
+ PipelineStatusName.STOPPED,
+]
+
+export type PipelineDisplayStateKey =
+ | 'starting'
+ | 'stopping'
+ | 'restarting'
+ | 'failed'
+ | 'stopped'
+ | 'running'
+ | 'unknown'
-const PIPELINE_STATE_MESSAGES = {
- enabling: {
+export type PipelineDisplayType = 'failure' | 'loading' | 'success' | 'idle'
+
+export interface PipelineDisplayState {
+ key: PipelineDisplayStateKey
+ label: string
+ title: string
+ message: string
+ badge: string
+ type: PipelineDisplayType
+}
+
+const PIPELINE_DISPLAY_STATES: Record<PipelineDisplayStateKey, PipelineDisplayState> = {
+ starting: {
+ key: 'starting',
+ label: 'Starting',
title: 'Starting pipeline',
message: 'Starting the pipeline. Replication will resume once running.',
badge: 'Starting',
+ type: 'loading',
},
- disabling: {
+ stopping: {
+ key: 'stopping',
+ label: 'Stopping',
title: 'Stopping pipeline',
- message: 'Stopping the pipeline. Replication will be paused once stopped.',
+ message: 'Stopping replication. Data transfer will be paused once stopped.',
badge: 'Stopping',
+ type: 'loading',
},
restarting: {
+ key: 'restarting',
+ label: 'Restarting',
title: 'Restarting pipeline',
message: 'Applying settings and restarting the pipeline.',
badge: 'Restarting',
+ type: 'loading',
},
failed: {
+ key: 'failed',
+ label: 'Failed',
title: 'Pipeline failed',
message: 'Replication has encountered an error.',
badge: 'Failed',
+ type: 'failure',
},
stopped: {
+ key: 'stopped',
+ label: 'Stopped',
title: 'Pipeline stopped',
message: 'Replication is paused. Start the pipeline to resume data synchronization.',
badge: 'Stopped',
- },
- starting: {
- title: 'Pipeline starting',
- message: 'Initializing replication. Table status will be available once running.',
- badge: 'Starting',
- },
- stopping: {
- title: 'Pipeline stopping',
- message: 'Stopping replication. Data transfer will be paused once stopped',
- badge: 'Stopping',
+ type: 'idle',
},
running: {
+ key: 'running',
+ label: 'Running',
title: 'Pipeline running',
- message: 'Replication is active and processing changes',
+ message: 'Replication is active and processing changes.',
badge: 'Running',
+ type: 'success',
},
unknown: {
+ key: 'unknown',
+ label: 'Unknown',
title: 'Pipeline status unknown',
message: 'Unable to determine pipeline status.',
badge: 'Unknown',
+ type: 'idle',
},
- notRunning: {
- title: 'Pipeline not running',
- message: 'Replication is not active. Start the pipeline to begin data synchronization.',
- badge: 'Stopped',
- },
-} as const
+}
-export const getPipelineStateMessages = (
+export const getPipelineDisplayState = (
requestStatus?: PipelineStatusRequestStatus,
- statusName?: ReplicationPipelineStatus
-) => {
- // Reflect optimistic request intent immediately after click
+ statusName?: PipelineStatusName
+): PipelineDisplayState => {
if (requestStatus === PipelineStatusRequestStatus.RestartRequested) {
- return PIPELINE_STATE_MESSAGES.restarting
+ return PIPELINE_DISPLAY_STATES.restarting
}
if (requestStatus === PipelineStatusRequestStatus.StartRequested) {
- return PIPELINE_STATE_MESSAGES.enabling
+ return PIPELINE_DISPLAY_STATES.starting
}
if (requestStatus === PipelineStatusRequestStatus.StopRequested) {
- return PIPELINE_STATE_MESSAGES.disabling
+ return PIPELINE_DISPLAY_STATES.stopping
}
- // Fall back to steady states
switch (statusName) {
- case 'starting':
- return PIPELINE_STATE_MESSAGES.starting
- case 'failed':
- return PIPELINE_STATE_MESSAGES.failed
- case 'stopped':
- return PIPELINE_STATE_MESSAGES.stopped
- case 'started':
- return PIPELINE_STATE_MESSAGES.running
- case 'stopping':
- return PIPELINE_STATE_MESSAGES.stopping
- case 'unknown':
- return PIPELINE_STATE_MESSAGES.unknown
+ case PipelineStatusName.STARTING:
+ return PIPELINE_DISPLAY_STATES.starting
+ case PipelineStatusName.FAILED:
+ return PIPELINE_DISPLAY_STATES.failed
+ case PipelineStatusName.STOPPED:
+ return PIPELINE_DISPLAY_STATES.stopped
+ case PipelineStatusName.STARTED:
+ return PIPELINE_DISPLAY_STATES.running
+ case PipelineStatusName.STOPPING:
+ return PIPELINE_DISPLAY_STATES.stopping
+ case PipelineStatusName.UNKNOWN:
default:
- return PIPELINE_STATE_MESSAGES.notRunning
+ return PIPELINE_DISPLAY_STATES.unknown
}
}
diff --git a/apps/studio/components/interfaces/Database/Replication/PipelineStatus.tsx b/apps/studio/components/interfaces/Database/Replication/PipelineStatus.tsx
index 453ce729e05..dcf28a2106b 100644
--- a/apps/studio/components/interfaces/Database/Replication/PipelineStatus.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/PipelineStatus.tsx
@@ -3,7 +3,7 @@ import { Loader2 } from 'lucide-react'
import { Badge, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
-import { getPipelineStateMessages } from './Pipeline.utils'
+import { getPipelineDisplayState, getStatusName } from './Pipeline.utils'
import { PipelineStatusName } from './Replication.constants'
import { InlineLink } from '@/components/ui/InlineLink'
import { ReplicationPipelineStatusData } from '@/data/replication/pipeline-status-query'
@@ -31,56 +31,9 @@ export const PipelineStatus = ({
}: PipelineStatusProps) => {
const { ref } = useParams()
- // Map backend statuses to UX-friendly display
- const getStatusConfig = (): {
- label: string
- type?: 'failure' | 'warning' | 'loading' | 'success' | 'idle'
- tooltip: string
- } => {
- const statusName =
- pipelineStatus && typeof pipelineStatus === 'object' && 'name' in pipelineStatus
- ? pipelineStatus.name
- : undefined
-
- // Get consistent tooltip message using the same logic as other components
- const stateMessages = getPipelineStateMessages(requestStatus, statusName)
-
- // Show optimistic request state while backend still reports steady states
- switch (requestStatus) {
- case PipelineStatusRequestStatus.RestartRequested:
- return { label: 'Restarting', type: 'loading', tooltip: stateMessages.message }
- case PipelineStatusRequestStatus.StartRequested:
- return { label: 'Starting', type: 'loading', tooltip: stateMessages.message }
- case PipelineStatusRequestStatus.StopRequested:
- return { label: 'Stopping', type: 'loading', tooltip: stateMessages.message }
- }
-
- if (pipelineStatus && typeof pipelineStatus === 'object' && 'name' in pipelineStatus) {
- switch (pipelineStatus.name) {
- case PipelineStatusName.FAILED:
- return { label: 'Failed', type: 'failure', tooltip: stateMessages.message }
- case PipelineStatusName.STARTING:
- return { label: 'Starting', type: 'loading', tooltip: stateMessages.message }
- case PipelineStatusName.STARTED:
- return { label: 'Running', type: 'success', tooltip: stateMessages.message }
- case PipelineStatusName.STOPPED:
- return { label: 'Stopped', type: 'idle', tooltip: stateMessages.message }
- case PipelineStatusName.STOPPING:
- return { label: 'Stopping', type: 'loading', tooltip: stateMessages.message }
- default:
- return { label: 'Unknown', type: 'idle', tooltip: stateMessages.message }
- }
- }
-
- // Fallback for undefined or invalid status
- return {
- label: 'Unknown',
- type: 'idle',
- tooltip: 'Pipeline status is unclear - check logs for details',
- }
- }
-
- const { type, tooltip, label } = getStatusConfig()
+ const statusName = getStatusName(pipelineStatus)
+ const displayState = getPipelineDisplayState(requestStatus, statusName)
+ const { type, message, label } = displayState
const pipelineLogsUrl = pipelineId
? `/project/${ref}/logs/replication-logs?f=${encodeURIComponent(
@@ -88,6 +41,10 @@ export const PipelineStatus = ({
)}`
: `/project/${ref}/logs/replication-logs`
+ const showLogsCTA = [PipelineStatusName.UNKNOWN, PipelineStatusName.FAILED].includes(
+ statusName as PipelineStatusName
+ )
+
return (
<>
{isLoading && <ShimmeringLoader />}
@@ -109,13 +66,7 @@ export const PipelineStatus = ({
<div className="flex items-center gap-x-2">
<Badge
variant={
- type === 'failure'
- ? 'destructive'
- : type === 'warning'
- ? 'warning'
- : type === 'success'
- ? 'success'
- : 'default'
+ type === 'failure' ? 'destructive' : type === 'success' ? 'success' : 'default'
}
>
{label}
@@ -124,8 +75,8 @@ export const PipelineStatus = ({
</div>
</TooltipTrigger>
<TooltipContent side="bottom">
- {tooltip}{' '}
- {['unknown', 'failed'].includes(pipelineStatus?.name ?? '') && (
+ {message}{' '}
+ {showLogsCTA && (
<>
Check the <InlineLink href={pipelineLogsUrl}>logs</InlineLink> for more information.
</>
diff --git a/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.tsx b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.tsx
index f9f2d6be254..0f32addeece 100644
--- a/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.tsx
@@ -23,7 +23,6 @@ import {
CardContent,
DropdownMenu,
DropdownMenuContent,
- DropdownMenuItem,
DropdownMenuTrigger,
Table,
TableBody,
@@ -37,6 +36,7 @@ import { Input } from 'ui-patterns/DataInputs/Input'
import { BatchRestartDialog } from '../BatchRestartDialog'
import { ErrorDetailsDialog } from '../ErrorDetailsDialog'
import {
+ getPipelineDisplayState,
getStatusName,
PIPELINE_ACTIONABLE_STATES,
PIPELINE_ERROR_MESSAGES,
@@ -49,7 +49,8 @@ import { SlotLagMetrics } from './ReplicationPipelineStatus.types'
import { getDisabledStateConfig } from './ReplicationPipelineStatus.utils'
import { SlotLagMetricsInline, SlotLagMetricsList } from './SlotLagMetrics'
import { TableReplicationRow } from './TableReplicationRow'
-import AlertError from '@/components/ui/AlertError'
+import { AlertError } from '@/components/ui/AlertError'
+import { DropdownMenuItemTooltip } from '@/components/ui/DropdownMenuItemTooltip'
import { useReplicationPipelineByIdQuery } from '@/data/replication/pipeline-by-id-query'
import { useReplicationPipelineReplicationStatusQuery } from '@/data/replication/pipeline-replication-status-query'
import { useReplicationPipelineStatusQuery } from '@/data/replication/pipeline-status-query'
@@ -138,6 +139,7 @@ export const ReplicationPipelineStatus = () => {
const destinationName = pipeline?.destination_name
const statusName = getStatusName(pipelineStatusData?.status)
+ const displayState = getPipelineDisplayState(requestStatus, statusName)
const config = getDisabledStateConfig({ requestStatus, statusName })
// Sort tables by name for consistent ordering (memoized)
@@ -181,13 +183,23 @@ export const ReplicationPipelineStatus = () => {
const hasErroredTables = erroredTables.length > 0
const isAnyRestartInProgress = restartingTableIds.size > 0
- const isPipelineRunning = statusName === 'started'
const hasTableData = tableStatuses.length > 0
+ const isPipelineActionable =
+ statusName === PipelineStatusName.STARTED ||
+ statusName === PipelineStatusName.STOPPED ||
+ statusName === PipelineStatusName.FAILED
const isEnablingDisabling =
requestStatus === PipelineStatusRequestStatus.StartRequested ||
requestStatus === PipelineStatusRequestStatus.StopRequested ||
requestStatus === PipelineStatusRequestStatus.RestartRequested
- const showDisabledState = !isPipelineRunning || isEnablingDisabling
+ const isPipelineBusy = isEnablingDisabling || isAnyRestartInProgress
+ const showDisabledState = isPipelineBusy || !isPipelineActionable
+ const lastKnownStateMessage =
+ statusName === PipelineStatusName.STOPPED
+ ? 'Showing the last known table state before the pipeline was stopped.'
+ : statusName === PipelineStatusName.FAILED
+ ? 'Showing the last reported table state before the pipeline failed.'
+ : null
const refreshIntervalLabel =
STATUS_REFRESH_FREQUENCY_MS >= 1000
? `${Math.round(STATUS_REFRESH_FREQUENCY_MS / 1000)}s`
@@ -197,21 +209,22 @@ export const ReplicationPipelineStatus = () => {
pipelineId ? `?f=${encodeURIComponent(JSON.stringify({ pipeline_id: pipelineId }))}` : ''
}`
- const label =
- statusName === 'stopped'
+ const label = isEnablingDisabling
+ ? displayState.label
+ : statusName === PipelineStatusName.STOPPED
? 'Start'
- : statusName === 'started'
+ : statusName === PipelineStatusName.STARTED
? 'Stop'
- : statusName === 'failed'
+ : statusName === PipelineStatusName.FAILED
? 'Restart'
- : statusName
+ : displayState.label
const icon =
- statusName === 'stopped' ? (
+ statusName === PipelineStatusName.STOPPED ? (
<Play />
- ) : statusName === 'started' ? (
+ ) : statusName === PipelineStatusName.STARTED ? (
<Pause />
- ) : statusName === 'failed' ? (
+ ) : statusName === PipelineStatusName.FAILED ? (
<RotateCcw />
) : (
<Ban />
@@ -222,17 +235,18 @@ export const ReplicationPipelineStatus = () => {
if (!pipeline) return toast.error(PIPELINE_ERROR_MESSAGES.NO_PIPELINE_FOUND)
try {
- if (statusName === 'stopped') {
+ if (statusName === PipelineStatusName.STOPPED) {
setRequestStatus(pipeline.id, PipelineStatusRequestStatus.StartRequested, statusName)
await startPipeline({ projectRef, pipelineId: pipeline.id })
- } else if (statusName === 'started') {
+ } else if (statusName === PipelineStatusName.STARTED) {
setRequestStatus(pipeline.id, PipelineStatusRequestStatus.StopRequested, statusName)
await stopPipeline({ projectRef, pipelineId: pipeline.id })
- } else if (statusName === 'failed') {
+ } else if (statusName === PipelineStatusName.FAILED) {
setRequestStatus(pipeline.id, PipelineStatusRequestStatus.RestartRequested, statusName)
await restartPipeline({ projectRef, pipelineId: pipeline.id })
}
} catch (error) {
+ setRequestStatus(pipeline.id, PipelineStatusRequestStatus.None)
toast.error(PIPELINE_ERROR_MESSAGES.ENABLE_DESTINATION)
}
}
@@ -279,11 +293,18 @@ export const ReplicationPipelineStatus = () => {
</Button>
<Button
- type={statusName === 'stopped' ? 'primary' : 'default'}
+ type={statusName === PipelineStatusName.STOPPED ? 'primary' : 'default'}
onClick={onPrimaryAction}
- loading={isPipelineError || isStartingPipeline || isStoppingPipeline}
- disabled={
+ loading={
+ isPipelineError ||
+ displayState.type === 'loading' ||
isEnablingDisabling ||
+ isStartingPipeline ||
+ isStoppingPipeline ||
+ isAnyRestartInProgress
+ }
+ disabled={
+ isPipelineBusy ||
!PIPELINE_ACTIONABLE_STATES.includes(statusName as PipelineStatusName)
}
icon={icon}
@@ -366,7 +387,7 @@ export const ReplicationPipelineStatus = () => {
</div>
)}
- {hasTableData && (
+ {!isPipelineLoading && !isStatusLoading && hasTableData && (
<div className="flex flex-col gap-y-3">
<div className="flex items-center justify-between">
<Input
@@ -389,46 +410,58 @@ export const ReplicationPipelineStatus = () => {
]
}
/>
- {!showDisabledState && (
- <div className="flex items-center">
- <Button
- size="tiny"
- type="default"
- className="rounded-r-none hover:z-[2]"
- icon={<RotateCcw />}
- disabled={tableStatuses.length === 0 || isAnyRestartInProgress}
- loading={isAnyRestartInProgress}
- onClick={() => {
- setBatchRestartMode('all')
- setShowBatchRestartDialog(true)
- }}
- >
- Restart all tables
- </Button>
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button
- type="default"
- icon={<ChevronDown />}
- className="w-7 rounded-l-none -ml-[1px]"
- />
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end" className="w-44">
- <DropdownMenuItem
- disabled={!hasErroredTables || isAnyRestartInProgress}
- onClick={() => {
- setBatchRestartMode('errored')
- setShowBatchRestartDialog(true)
- }}
- >
- Restart failed tables only
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- </div>
- )}
+ <div className="flex items-center">
+ <Button
+ size="tiny"
+ type="default"
+ className="rounded-r-none hover:z-[2]"
+ icon={<RotateCcw />}
+ disabled={isAnyRestartInProgress || showDisabledState || isPipelineError}
+ loading={isAnyRestartInProgress}
+ onClick={() => {
+ setBatchRestartMode('all')
+ setShowBatchRestartDialog(true)
+ }}
+ >
+ Restart all tables
+ </Button>
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button
+ type="default"
+ icon={<ChevronDown />}
+ className="w-7 rounded-l-none -ml-[1px]"
+ disabled={showDisabledState || isPipelineError}
+ />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end" className="w-44">
+ <DropdownMenuItemTooltip
+ disabled={!hasErroredTables || isAnyRestartInProgress || showDisabledState}
+ onClick={() => {
+ setBatchRestartMode('errored')
+ setShowBatchRestartDialog(true)
+ }}
+ tooltip={{
+ content: {
+ side: 'left',
+ text: hasErroredTables ? 'No tables require manual retry' : undefined,
+ },
+ }}
+ >
+ Restart failed tables only
+ </DropdownMenuItemTooltip>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </div>
</div>
+ {lastKnownStateMessage !== null && !showDisabledState && (
+ <div className="flex items-start gap-2 rounded-md border border-default/50 bg-surface-200/60 px-3 py-2 text-xs text-foreground-light">
+ <Info size={14} className="mt-0.5" />
+ <span>{lastKnownStateMessage}</span>
+ </div>
+ )}
+
<Card>
<CardContent className="p-0">
<Table>
@@ -452,9 +485,11 @@ export const ReplicationPipelineStatus = () => {
<TableReplicationRow
key={table.table_id}
table={table}
- config={config}
isRestarting={isRestarting}
showDisabledState={showDisabledState}
+ disabledStateMessage={config.message}
+ isAnyRestartInProgress={isAnyRestartInProgress}
+ isPipelineStopped={statusName === PipelineStatusName.STOPPED}
onSelectRestart={() => {
setSelectedTableForRestart({
tableId: table.table_id,
@@ -484,7 +519,7 @@ export const ReplicationPipelineStatus = () => {
</div>
)}
- {!isStatusLoading && tableStatuses.length === 0 && (
+ {!isPipelineLoading && !isStatusLoading && tableStatuses.length === 0 && (
<div className="flex flex-col items-center justify-center py-16 px-4 border rounded-lg border-dashed">
<div className="w-full max-w-sm mx-auto text-center space-y-4">
<div className="w-16 h-16 bg-surface-200 rounded-full flex items-center justify-center mx-auto">
@@ -492,18 +527,29 @@ export const ReplicationPipelineStatus = () => {
</div>
<div className="space-y-2">
<h4 className="text-lg font-semibold text-foreground">
- {showDisabledState ? 'Pipeline not running' : 'No table status information'}
+ {showDisabledState
+ ? config.title
+ : statusName === PipelineStatusName.STOPPED
+ ? 'Pipeline stopped'
+ : statusName === PipelineStatusName.FAILED
+ ? 'Pipeline failed'
+ : 'No table data yet'}
</h4>
<p className="text-sm text-foreground-light leading-relaxed">
{showDisabledState
- ? `The replication pipeline is currently ${statusName || 'not active'}. Table status
- information is not available while the pipeline is in this state.`
- : `This pipeline doesn't have any table replication status data available yet. The status will appear here once replication begins.`}
+ ? config.message
+ : statusName === PipelineStatusName.STOPPED
+ ? 'Start the pipeline to begin replication.'
+ : statusName === PipelineStatusName.FAILED
+ ? 'The pipeline encountered an error. Restart it or reset your tables to recover.'
+ : 'Table status will appear here once replication begins.'}
</p>
</div>
- <p className="text-xs text-foreground-lighter">
- Data refreshes automatically every 2 seconds
- </p>
+ {statusName !== PipelineStatusName.STOPPED && (
+ <p className="text-xs text-foreground-lighter">
+ Data refreshes every {refreshIntervalLabel}
+ </p>
+ )}
</div>
</div>
)}
@@ -527,6 +573,7 @@ export const ReplicationPipelineStatus = () => {
onOpenChange={setShowRestartDialog}
tableId={selectedTableForRestart.tableId}
tableName={selectedTableForRestart.tableName}
+ pipelineStatusName={statusName}
onRestartStart={() => {
setRestartingTableIds((prev) => new Set(prev).add(selectedTableForRestart.tableId))
}}
@@ -560,6 +607,7 @@ export const ReplicationPipelineStatus = () => {
totalTables={tableStatuses.length}
erroredTablesCount={erroredTables.length}
tables={tableStatuses}
+ pipelineStatusName={statusName}
onRestartStart={(tableIds) => {
setRestartingTableIds((prev) => new Set([...prev, ...tableIds]))
}}
diff --git a/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.utils.tsx b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.utils.tsx
index 452b4a9e859..525b86de9ef 100644
--- a/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.utils.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.utils.tsx
@@ -1,8 +1,7 @@
import dayjs from 'dayjs'
-import { Activity, Clock, HelpCircle, Loader2, XCircle } from 'lucide-react'
import { Badge } from 'ui'
-import { getPipelineStateMessages } from '../Pipeline.utils'
+import { getPipelineDisplayState, normalizePipelineStatusName } from '../Pipeline.utils'
import { RetryPolicy, TableState } from './ReplicationPipelineStatus.types'
import { ReplicationPipelineStatusData } from '@/data/replication/pipeline-status-query'
import { formatBytes } from '@/lib/helpers'
@@ -64,60 +63,11 @@ export const getDisabledStateConfig = ({
requestStatus: PipelineStatusRequestStatus
statusName?: ReplicationPipelineStatusData['status']['name']
}) => {
- const { title, message, badge } = getPipelineStateMessages(requestStatus, statusName)
-
- // Get icon and colors based on current state
- const isEnabling = requestStatus === PipelineStatusRequestStatus.StartRequested
- const isDisabling = requestStatus === PipelineStatusRequestStatus.StopRequested
- const isRestarting = requestStatus === PipelineStatusRequestStatus.RestartRequested
- const isTransitioning = isEnabling || isDisabling || isRestarting
-
- const icon = isTransitioning ? (
- <Loader2 className="w-6 h-6 animate-spin" />
- ) : statusName === 'failed' ? (
- <XCircle className="w-6 h-6" />
- ) : statusName === 'starting' ? (
- <Clock className="w-6 h-6" />
- ) : statusName === 'unknown' ? (
- <HelpCircle className="w-6 h-6" />
- ) : (
- <Activity className="w-6 h-6" />
- )
-
- const colors =
- isEnabling || isRestarting
- ? {
- bg: 'bg-brand-50',
- text: 'text-brand-900',
- subtext: 'text-brand-700',
- iconBg: 'bg-brand-600',
- icon: 'text-white dark:text-black',
- }
- : isDisabling || statusName === 'starting' || statusName === 'unknown'
- ? {
- bg: 'bg-warning-50',
- text: 'text-warning-900',
- subtext: 'text-warning-700',
- iconBg: 'bg-warning-600',
- icon: 'text-white dark:text-black',
- }
- : statusName === 'failed'
- ? {
- bg: 'bg-destructive-50',
- text: 'text-destructive-900',
- subtext: 'text-destructive-700',
- iconBg: 'bg-destructive-600',
- icon: 'text-white dark:text-black',
- }
- : {
- bg: 'bg-surface-100',
- text: 'text-foreground',
- subtext: 'text-foreground-light',
- iconBg: 'bg-foreground-lighter',
- icon: 'text-white dark:text-black',
- }
-
- return { title, message, badge, icon, colors }
+ const normalizedStatusName = normalizePipelineStatusName(statusName)
+ const displayState = getPipelineDisplayState(requestStatus, normalizedStatusName)
+ const { title, message } = displayState
+
+ return { title, message }
}
export const isValidRetryPolicy = (policy: any): policy is RetryPolicy => {
diff --git a/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/TableReplicationRow.tsx b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/TableReplicationRow.tsx
index bbfb957cd36..68f5d2d6248 100644
--- a/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/TableReplicationRow.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/TableReplicationRow.tsx
@@ -1,29 +1,33 @@
import { useParams } from 'common'
import { ExternalLink, RotateCcw } from 'lucide-react'
import Link from 'next/link'
-import { Badge, Button, cn, TableCell, TableRow, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
+import { Badge, Button, TableCell, TableRow, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
import { ErroredTableDetails } from '../ErroredTableDetails'
import { TableState } from './ReplicationPipelineStatus.types'
-import { getDisabledStateConfig, getStatusConfig } from './ReplicationPipelineStatus.utils'
+import { getStatusConfig } from './ReplicationPipelineStatus.utils'
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
import { InlineLinkClassName } from '@/components/ui/InlineLink'
import { ReplicationPipelineTableStatus } from '@/data/replication/pipeline-replication-status-query'
interface TableReplicationRowProps {
table: ReplicationPipelineTableStatus
- config: ReturnType<typeof getDisabledStateConfig>
isRestarting: boolean
showDisabledState: boolean
+ disabledStateMessage: string
+ isAnyRestartInProgress: boolean
+ isPipelineStopped: boolean
onSelectRestart: () => void
onSelectShowError: () => void
}
export const TableReplicationRow = ({
table,
- config,
isRestarting,
showDisabledState,
+ disabledStateMessage,
+ isAnyRestartInProgress,
+ isPipelineStopped,
onSelectRestart,
onSelectShowError,
}: TableReplicationRowProps) => {
@@ -35,7 +39,7 @@ export const TableReplicationRow = ({
<TableRow>
<TableCell className="align-top">
<div className="flex items-center gap-x-2">
- <p className={cn(isRestarting && 'text-foreground-light')}>{table.table_name}</p>
+ <p>{table.table_name}</p>
<ButtonTooltip
asChild
@@ -71,9 +75,7 @@ export const TableReplicationRow = ({
Replication is being restarted for this table. The pipeline will restart automatically.
</p>
) : showDisabledState ? (
- <p className="text-sm text-foreground-lighter">
- Status unavailable while pipeline is {config.badge.toLowerCase()}
- </p>
+ <p className="text-sm text-foreground-lighter">{disabledStateMessage}</p>
) : (
<div className="flex flex-col gap-y-3">
<div className="text-sm text-foreground">
@@ -97,13 +99,13 @@ export const TableReplicationRow = ({
type="default"
className="w-7"
icon={<RotateCcw />}
- disabled={showDisabledState || isRestarting}
+ disabled={showDisabledState || isRestarting || isAnyRestartInProgress}
aria-label={`Restart replication for ${table.table_name}`}
onClick={onSelectRestart}
/>
</TooltipTrigger>
<TooltipContent side="bottom" align="center">
- Restart table replication
+ {isPipelineStopped ? 'Reset table and start pipeline' : 'Reset and restart pipeline'}
</TooltipContent>
</Tooltip>
</div>
diff --git a/apps/studio/components/interfaces/Database/Replication/RestartTableDialog.tsx b/apps/studio/components/interfaces/Database/Replication/RestartTableDialog.tsx
index 275fb5bfa13..d8bc697e96f 100644
--- a/apps/studio/components/interfaces/Database/Replication/RestartTableDialog.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/RestartTableDialog.tsx
@@ -11,6 +11,7 @@ import {
AlertDialogTitle,
} from 'ui'
+import { PipelineStatusName } from './Replication.constants'
import { useRollbackTablesMutation } from '@/data/replication/rollback-tables-mutation'
interface RestartTableDialogProps {
@@ -18,6 +19,7 @@ interface RestartTableDialogProps {
onOpenChange: (open: boolean) => void
tableId: number
tableName: string
+ pipelineStatusName?: PipelineStatusName
onRestartStart?: () => void
onRestartComplete?: () => void
}
@@ -27,6 +29,7 @@ export const RestartTableDialog = ({
onOpenChange,
tableId,
tableName,
+ pipelineStatusName,
onRestartStart,
onRestartComplete,
}: RestartTableDialogProps) => {
@@ -36,15 +39,15 @@ export const RestartTableDialog = ({
const { mutate: rollbackTables, isPending: isResetting } = useRollbackTablesMutation({
onSuccess: () => {
toast.success(
- `Restarting replication for "${tableName}". Pipeline will restart automatically.`
+ `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}`)
- onRestartComplete?.()
- onOpenChange(false)
},
})
@@ -58,6 +61,7 @@ export const RestartTableDialog = ({
pipelineId,
target: { type: 'single_table', table_id: tableId },
rollbackType: 'full',
+ pipelineStatusName,
})
}
diff --git a/apps/studio/data/replication/restart-pipeline-helper.ts b/apps/studio/data/replication/restart-pipeline-helper.ts
index ca429273e20..881f1aa8c47 100644
--- a/apps/studio/data/replication/restart-pipeline-helper.ts
+++ b/apps/studio/data/replication/restart-pipeline-helper.ts
@@ -1,7 +1,7 @@
import { useStartPipelineMutation } from './start-pipeline-mutation'
import { useStopPipelineMutation } from './stop-pipeline-mutation'
-export interface RestartPipelineParams {
+interface RestartPipelineParams {
projectRef: string
pipelineId: number
}
diff --git a/apps/studio/data/replication/rollback-tables-mutation.ts b/apps/studio/data/replication/rollback-tables-mutation.ts
index c6a8b1676fd..3ab727bbf72 100644
--- a/apps/studio/data/replication/rollback-tables-mutation.ts
+++ b/apps/studio/data/replication/rollback-tables-mutation.ts
@@ -2,7 +2,9 @@ import { useMutation, useQueryClient } from '@tanstack/react-query'
import { toast } from 'sonner'
import { replicationKeys } from './keys'
-import { useRestartPipelineHelper } from './restart-pipeline-helper'
+import { startPipeline } from './start-pipeline-mutation'
+import { stopPipeline } from './stop-pipeline-mutation'
+import { PipelineStatusName } from '@/components/interfaces/Database/Replication/Replication.constants'
import { handleError, post } from '@/data/fetchers'
import type { ResponseError, UseCustomMutationOptions } from '@/types'
@@ -18,6 +20,7 @@ type RollbackTablesParams = {
pipelineId: number
target: RollbackTablesTarget
rollbackType: RollbackType
+ pipelineStatusName?: PipelineStatusName
}
type RolledBackTable = {
@@ -34,7 +37,7 @@ type RollbackTablesResponse = {
}
async function rollbackTables(
- { projectRef, pipelineId, target, rollbackType }: RollbackTablesParams,
+ { projectRef, pipelineId, target, rollbackType, pipelineStatusName }: RollbackTablesParams,
signal?: AbortSignal
): Promise<RollbackTablesResponse> {
if (!projectRef) throw new Error('Project reference is required')
@@ -49,8 +52,42 @@ async function rollbackTables(
signal,
}
)
-
if (error) handleError(error)
+
+ // Logic for starting the pipeline back up after a successfull rollback
+ if (pipelineStatusName) {
+ const shouldStartPipelineAfterRollback = [
+ PipelineStatusName.STOPPED,
+ PipelineStatusName.STARTED,
+ PipelineStatusName.FAILED,
+ ].includes(pipelineStatusName)
+
+ try {
+ if (pipelineStatusName === PipelineStatusName.STOPPED) {
+ await startPipeline({ projectRef, pipelineId })
+ } else if (
+ pipelineStatusName === PipelineStatusName.STARTED ||
+ pipelineStatusName === PipelineStatusName.FAILED
+ ) {
+ await stopPipeline({ projectRef, pipelineId })
+ await startPipeline({ projectRef, pipelineId })
+ } else {
+ // [Joshen] This error sounds misleading as though the rollback failed?
+ throw new Error(
+ `Cannot apply rollback while pipeline status is ${
+ pipelineStatusName || 'unknown'
+ }. Retry once the pipeline status is started, failed, or stopped.`
+ )
+ }
+ } catch (error) {
+ if (shouldStartPipelineAfterRollback) {
+ throw new Error('RESTART_FAILED', { cause: error })
+ } else {
+ throw new Error('RESTART_SKIPPED')
+ }
+ }
+ }
+
return data
}
@@ -65,22 +102,11 @@ export const useRollbackTablesMutation = ({
'mutationFn'
> = {}) => {
const queryClient = useQueryClient()
- const { restartPipeline } = useRestartPipelineHelper()
return useMutation<RollbackTablesData, ResponseError, RollbackTablesParams>({
mutationFn: (vars) => rollbackTables(vars),
async onSuccess(data, variables, context) {
- const { projectRef, pipelineId } = variables
-
- // Restart the pipeline (stop + start)
- try {
- await restartPipeline({ projectRef, pipelineId })
- } catch (error: any) {
- toast.error(`Rollback succeeded but failed to restart pipeline: ${error.message}`)
- throw error
- }
-
- // Invalidate queries after restart to get the latest state
+ const { projectRef, pipelineId, pipelineStatusName } = variables
await Promise.all([
queryClient.invalidateQueries({
queryKey: replicationKeys.pipelinesStatus(projectRef, pipelineId),
@@ -89,12 +115,23 @@ export const useRollbackTablesMutation = ({
queryKey: replicationKeys.pipelinesReplicationStatus(projectRef, pipelineId),
}),
])
-
await onSuccess?.(data, variables, context)
},
async onError(data, variables, context) {
if (onError === undefined) {
- toast.error(`Failed to rollback tables: ${data.message}`)
+ if (data.message === 'RESTART_FAILED') {
+ const cause = (data as Error).cause
+ const causeMessage = cause instanceof Error ? cause.message : undefined
+ toast.error(
+ `Rollback completed, but failed to start the pipeline${causeMessage ? `: ${causeMessage}` : ''}`
+ )
+ } else if (data.message === 'RESTART_SKIPPED') {
+ toast(
+ 'Rollback completed, but the pipeline state changed before it could be resumed. Refresh the page and try again.'
+ )
+ } else {
+ toast.error(`Failed to rollback tables: ${data.message}`)
+ }
} else {
onError(data, variables, context)
}
diff --git a/apps/studio/data/replication/start-pipeline-mutation.ts b/apps/studio/data/replication/start-pipeline-mutation.ts
index b6dd879e14f..bc2e72ea132 100644
--- a/apps/studio/data/replication/start-pipeline-mutation.ts
+++ b/apps/studio/data/replication/start-pipeline-mutation.ts
@@ -10,7 +10,7 @@ export type StartPipelineParams = {
pipelineId: number
}
-async function startPipeline(
+export async function startPipeline(
{ projectRef, pipelineId }: StartPipelineParams,
signal?: AbortSignal
) {
diff --git a/apps/studio/data/replication/stop-pipeline-mutation.ts b/apps/studio/data/replication/stop-pipeline-mutation.ts
index a330c44cf06..7dd1b080365 100644
--- a/apps/studio/data/replication/stop-pipeline-mutation.ts
+++ b/apps/studio/data/replication/stop-pipeline-mutation.ts
@@ -10,7 +10,10 @@ export type StopPipelineParams = {
pipelineId: number
}
-async function stopPipeline({ projectRef, pipelineId }: StopPipelineParams, signal?: AbortSignal) {
+export async function stopPipeline(
+ { projectRef, pipelineId }: StopPipelineParams,
+ signal?: AbortSignal
+) {
if (!projectRef) throw new Error('projectRef is required')
const { data, error } = await post('/platform/replication/{ref}/pipelines/{pipeline_id}/stop', {