mirror of
https://github.com/supabase/supabase.git
synced 2026-09-07 02:20:52 +08:00
## What kind of change does this PR introduce? Feature. Stack 3 of 5 for [PIPE-1007](https://linear.app/supabase/issue/PIPE-1007/move-read-replicas-out-of-replication-into-infrastructure). ## What is the current behavior? Replica detail lives at `/database/replication/replica/:id`. ## What is the new behavior? Detail moves to `/settings/infrastructure/replica/:id`. Old URLs redirect. List and diagram View/Manage replica links follow. ## Additional context Stacked on [#49044](https://github.com/supabase/supabase/pull/49044). Please review, but do not merge. Merge 2→5 in succession once they are all reviewed, so users never sit on a split create/list vs detail path. Replication still lists and creates replicas until [#49046](https://github.com/supabase/supabase/pull/49046). ## To test `infrastructure:read_replicas` is an enabled-feature, on by default. There is no Feature Preview or ConfigCat switch. You should already see the Infrastructure Read replicas section. If you do not, your profile lists `infrastructure:read_replicas` in `disabled_features`. From [Infrastructure](https://studio-staging-git-danny-pipe-1007-03-detail-redirects-supabase.vercel.app/dashboard/project/_/settings/infrastructure), open View replica on a row. Confirm you land on `/settings/infrastructure/replica/:id`. If you have an old bookmark, `/database/replication/replica/:id` should redirect there. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added read replica management to Infrastructure settings, including replica creation, status monitoring, details, restart, and removal actions. * Added eligibility guidance and estimated pricing details during replica setup. * Added support for topology and replica information within infrastructure configuration. * **Improvements** * Legacy database replication links now permanently redirect to the corresponding Infrastructure pages. * Added clearer empty, loading, error, and transition states for read replica management. * **Tests** * Expanded coverage for replica navigation, redirects, eligibility warnings, and empty states. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
161 lines
5.3 KiB
TypeScript
161 lines
5.3 KiB
TypeScript
import { useParams } from 'common'
|
|
import { Database as DatabaseIcon } from 'icons'
|
|
import { Loader2, Minus, MoreVertical, RotateCcw, Trash } from 'lucide-react'
|
|
import Link from 'next/link'
|
|
import { useMemo, useState } from 'react'
|
|
import { AWS_REGIONS } from 'shared-data'
|
|
import {
|
|
Badge,
|
|
Button,
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
TableCell,
|
|
TableRow,
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipTrigger,
|
|
} from 'ui'
|
|
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import { DropReplicaConfirmationModal } from './DropReplicaConfirmationModal'
|
|
import { REPLICA_STATUS } from './ReadReplicas.constants'
|
|
import { getIsInTransition, getStatusLabel } from './ReadReplicas.utils'
|
|
import { RestartReplicaConfirmationModal } from './RestartReplicaConfirmationModal'
|
|
import { getReadReplicaPath } from '@/components/interfaces/Settings/Infrastructure/Infrastructure.utils'
|
|
import { useReplicationLagQuery } from '@/data/read-replicas/replica-lag-query'
|
|
import { type Database } from '@/data/read-replicas/replicas-query'
|
|
import { formatDatabaseID } from '@/data/read-replicas/replicas.utils'
|
|
|
|
interface ReadReplicaRow {
|
|
replica: Database
|
|
onUpdateReplica: () => void
|
|
}
|
|
|
|
export const ReadReplicaRow = ({ replica, onUpdateReplica }: ReadReplicaRow) => {
|
|
const { ref } = useParams()
|
|
const { identifier, region, status } = replica
|
|
const formattedId = formatDatabaseID(identifier ?? '')
|
|
|
|
const {
|
|
data: lagDuration,
|
|
isPending: isLoadingLag,
|
|
isError: isErrorLag,
|
|
} = useReplicationLagQuery(
|
|
{
|
|
id: identifier,
|
|
projectRef: ref,
|
|
connectionString: replica.connectionString,
|
|
},
|
|
{ enabled: status === REPLICA_STATUS.ACTIVE_HEALTHY }
|
|
)
|
|
|
|
const [showConfirmRestart, setShowConfirmRestart] = useState(false)
|
|
const [showConfirmDrop, setShowConfirmDrop] = useState(false)
|
|
|
|
const regionMeta = Object.values(AWS_REGIONS).find((x) => x.code === region)
|
|
|
|
const isInTransition = useMemo(() => getIsInTransition({ status }), [status])
|
|
const statusLabel = useMemo(() => getStatusLabel({ status }), [status])
|
|
|
|
return (
|
|
<>
|
|
<TableRow>
|
|
<TableCell>
|
|
<DatabaseIcon size={18} className="text-foreground-light" />
|
|
</TableCell>
|
|
|
|
<TableCell>
|
|
<div>
|
|
<p>Read Replica (ID: {formattedId})</p>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<p className="text-foreground-lighter w-fit">{regionMeta?.displayName}</p>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="right">{regionMeta?.code}</TooltipContent>
|
|
</Tooltip>
|
|
</div>
|
|
</TableCell>
|
|
|
|
<TableCell>
|
|
<div className="flex items-center gap-x-2">
|
|
<Badge
|
|
variant={
|
|
statusLabel === 'Healthy'
|
|
? 'success'
|
|
: statusLabel === 'Failed'
|
|
? 'destructive'
|
|
: 'default'
|
|
}
|
|
>
|
|
{statusLabel}
|
|
</Badge>
|
|
{isInTransition && <Loader2 className="animate-spin w-3 h-3" />}
|
|
</div>
|
|
</TableCell>
|
|
|
|
<TableCell>
|
|
{isErrorLag || status !== REPLICA_STATUS.ACTIVE_HEALTHY ? (
|
|
<Minus size={18} className="text-foreground-lighter" />
|
|
) : isLoadingLag ? (
|
|
<ShimmeringLoader />
|
|
) : (
|
|
<p>{lagDuration}s</p>
|
|
)}
|
|
</TableCell>
|
|
|
|
<TableCell>
|
|
<div className="flex items-center justify-end gap-x-2">
|
|
<Button
|
|
asChild
|
|
variant="default"
|
|
className="relative"
|
|
disabled={status === 'GOING_DOWN'}
|
|
>
|
|
<Link href={getReadReplicaPath(ref, replica.identifier)}>View replica</Link>
|
|
</Button>
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button variant="default" icon={<MoreVertical />} className="w-7" />
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end" className="w-52">
|
|
<DropdownMenuItem
|
|
className="gap-x-2"
|
|
disabled={status !== 'ACTIVE_HEALTHY'}
|
|
onClick={() => setShowConfirmRestart(true)}
|
|
>
|
|
<RotateCcw size={14} />
|
|
<span>Restart replica</span>
|
|
</DropdownMenuItem>
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuItem
|
|
className="gap-x-2"
|
|
disabled={status === 'GOING_DOWN'}
|
|
onClick={() => setShowConfirmDrop(true)}
|
|
>
|
|
<Trash size={14} />
|
|
<span>Drop replica</span>
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</div>
|
|
</TableCell>
|
|
</TableRow>
|
|
|
|
<DropReplicaConfirmationModal
|
|
selectedReplica={showConfirmDrop ? replica : undefined}
|
|
onSuccess={() => onUpdateReplica()}
|
|
onCancel={() => setShowConfirmDrop(false)}
|
|
/>
|
|
|
|
<RestartReplicaConfirmationModal
|
|
selectedReplica={showConfirmRestart ? replica : undefined}
|
|
onSuccess={() => onUpdateReplica()}
|
|
onCancel={() => setShowConfirmRestart(false)}
|
|
/>
|
|
</>
|
|
)
|
|
}
|