The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Update physical backups enable flow for read replicas (#26981)
Joshen Lim403c981aae96
diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DeployNewReplicaPanel.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DeployNewReplicaPanel.tsxindex 529d02830e6..ec7066252fa 100644--- a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DeployNewReplicaPanel.tsx+++ b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DeployNewReplicaPanel.tsx@@ -1,17 +1,9 @@-import { useParams } from 'common'import { ExternalLink } from 'lucide-react'import Link from 'next/link'import { useEffect, useState } from 'react'import toast from 'react-hot-toast'-import {- AlertDescription_Shadcn_,- AlertTitle_Shadcn_,- Alert_Shadcn_,- Button,- Listbox,- SidePanel,-} from 'ui'+import { useParams } from 'common'import { useEnablePhysicalBackupsMutation } from 'data/database/enable-physical-backups-mutation'import { useProjectDetailQuery } from 'data/projects/project-detail-query'import { Region, useReadReplicaSetUpMutation } from 'data/read-replicas/replica-setup-mutation'@@ -20,6 +12,14 @@ import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-queimport { useProjectAddonsQuery } from 'data/subscriptions/project-addons-query'import { useSelectedOrganization, useSelectedProject } from 'hooks'import { AWS_REGIONS, AWS_REGIONS_DEFAULT, AWS_REGIONS_KEYS, BASE_PATH } from 'lib/constants'+import {+ AlertDescription_Shadcn_,+ AlertTitle_Shadcn_,+ Alert_Shadcn_,+ Button,+ Listbox,+ SidePanel,+} from 'ui'import { WarningIcon } from 'ui-patterns/Icons/StatusIcons'import { AVAILABLE_REPLICA_REGIONS, AWS_REGIONS_VALUES } from './InstanceConfiguration.constants'@@ -44,6 +44,9 @@ const DeployNewReplicaPanel = ({const [refetchInterval, setRefetchInterval] = useState<number | false>(false)const { data } = useReadReplicasQuery({ projectRef })+ const { data: addons, isSuccess } = useProjectAddonsQuery({ projectRef })+ const { data: subscription } = useOrgSubscriptionQuery({ orgSlug: org?.slug })+useProjectDetailQuery({ ref: projectRef },{@@ -55,9 +58,6 @@ const DeployNewReplicaPanel = ({})- const { data: addons, isSuccess } = useProjectAddonsQuery({ projectRef })- const { data: subscription } = useOrgSubscriptionQuery({ orgSlug: org?.slug })-const { mutate: enablePhysicalBackups, isLoading: isEnabling } = useEnablePhysicalBackupsMutation({onSuccess: () => {@@ -144,12 +144,32 @@ const DeployNewReplicaPanel = ({return (<SidePanelvisible={visible}- loading={isSettingUp}onCancel={onClose}- onConfirm={() => onSubmit()}- confirmText="Deploy replica"+ loading={isSettingUp}disabled={!canDeployReplica}header="Deploy a new read replica"+ onConfirm={() => onSubmit()}+ confirmText="Deploy replica"+ // [Joshen] Refer to EnablePhysicalBackupsModal as to why this is commented out for now+ // customFooter={+ // <div className="border-t p-2 flex items-center justify-end space-x-2">+ // <Button type="default" disabled={false} onClick={onClose}>+ // Cancel+ // </Button>+ // {isMinimallyOnSmallCompute && !isWalgEnabled ? (+ // <EnablePhysicalBackupsModal selectedRegion={selectedRegion} />+ // ) : (+ // <Button+ // type="primary"+ // disabled={!canDeployReplica}+ // loading={isSettingUp}+ // onClick={onSubmit}+ // >+ // Deploy replica+ // </Button>+ // )}+ // </div>+ // }><SidePanel.Content className="flex flex-col py-4 gap-y-4">{!isAWSProvider ? (@@ -199,7 +219,44 @@ const DeployNewReplicaPanel = ({</Alert_Shadcn_>) : (<>- {!isWalgEnabled && (+ {!isMinimallyOnSmallCompute && (+ <Alert_Shadcn_>+ <WarningIcon />+ <AlertTitle_Shadcn_>+ Project required to at least be on a Small compute+ </AlertTitle_Shadcn_>+ <AlertDescription_Shadcn_>+ <span>+ This is to ensure that read replicas can keep up with the primary databases'+ activities.+ </span>+ <div className="flex items-center gap-x-2 mt-3">+ <Button asChild type="default">+ <Link+ href={+ isFreePlan+ ? `/org/${org?.slug}/billing?panel=subscriptionPlan`+ : `/project/${projectRef}/settings/addons?panel=computeInstance`+ }+ >+ {isFreePlan ? 'Upgrade to Pro' : 'Change compute size'}+ </Link>+ </Button>+ <Button asChild type="default" icon={<ExternalLink size={14} />}>+ <a+ href="https://supabase.com/docs/guides/platform/read-replicas#prerequisites"+ target="_blank"+ rel="noreferrer"+ >+ Documentation+ </a>+ </Button>+ </div>+ </AlertDescription_Shadcn_>+ </Alert_Shadcn_>+ )}++ {isMinimallyOnSmallCompute && !isWalgEnabled && (<Alert_Shadcn_><WarningIcon /><AlertTitle_Shadcn_>@@ -248,37 +305,6 @@ const DeployNewReplicaPanel = ({</Alert_Shadcn_>)}- {!isMinimallyOnSmallCompute && (- <Alert_Shadcn_>- <WarningIcon />- <AlertTitle_Shadcn_>- Project required to at least be on a Small compute- </AlertTitle_Shadcn_>- <AlertDescription_Shadcn_>- <span>- This is to ensure that read replicas can keep up with the primary databases'- activities.- </span>- <div className="flex items-center gap-x-2 mt-3">- <Button asChild type="default">- <Link href={`/project/${projectRef}/settings/addons?panel=computeInstance`}>- Change compute size- </Link>- </Button>- <Button asChild type="default" icon={<ExternalLink size={14} />}>- <a- href="https://supabase.com/docs/guides/platform/read-replicas#prerequisites"- target="_blank"- rel="noreferrer"- >- Documentation- </a>- </Button>- </div>- </AlertDescription_Shadcn_>- </Alert_Shadcn_>- )}-{reachedMaxReplicas && (<Alert_Shadcn_><WarningIcon />diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/EnablePhysicalBackupsModal.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/EnablePhysicalBackupsModal.tsxnew file mode 100644index 00000000000..98e252b83f6--- /dev/null+++ b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/EnablePhysicalBackupsModal.tsx@@ -0,0 +1,147 @@+import { ExternalLink, Loader2 } from 'lucide-react'+import { useState } from 'react'+import toast from 'react-hot-toast'++import { useParams } from 'common'+import { Markdown } from 'components/interfaces/Markdown'+import { useEnablePhysicalBackupsMutation } from 'data/database/enable-physical-backups-mutation'+import { useProjectDetailQuery } from 'data/projects/project-detail-query'+import { Region, useReadReplicaSetUpMutation } from 'data/read-replicas/replica-setup-mutation'+import { useReadReplicasQuery } from 'data/read-replicas/replicas-query'+import {+ Button,+ Dialog,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogSection,+ DialogSectionSeparator,+ DialogTitle,+ DialogTrigger,+} from 'ui'+import { AVAILABLE_REPLICA_REGIONS, AWS_REGIONS_VALUES } from './InstanceConfiguration.constants'++interface EnablePhysicalBackupsModalProps {+ selectedRegion: string+}++// [Joshen] Just FYI while this is not being used, i'm opting to leave this in as this is IMO an ideal UX+// Problem right now is that we can't immediately initiate a new replica request once the physical backups+// flag is flipped to true as RRs still need a physical backup to be completed before setting an RR up+// i.e This UX will immediately show an error when the create replica request is triggered.+export const EnablePhysicalBackupsModal = ({ selectedRegion }: EnablePhysicalBackupsModalProps) => {+ const { ref } = useParams()+ const [open, setOpen] = useState(false)+ const [enabling, setEnabling] = useState(false)+ const [refetchInterval, setRefetchInterval] = useState<number | false>(false)++ const { data: databases } = useReadReplicasQuery({ projectRef: ref })++ useProjectDetailQuery(+ { ref },+ {+ refetchInterval,+ refetchOnWindowFocus: false,+ onSuccess: (data) => {+ if (data.is_physical_backups_enabled) {+ setRefetchInterval(false)+ const regionKey = AWS_REGIONS_VALUES[selectedRegion]++ if (ref === undefined) return toast.error('Project ref is required')+ if (!regionKey)+ return toast.error('Unable to deploy replica: Unsupported region selected')+ const primary = databases?.find((db) => db.identifier === ref)+ setUpReplica({+ projectRef: ref,+ region: regionKey as Region,+ size: primary?.size ?? 't4g.small',+ })+ }+ },+ }+ )++ const { mutate: enablePhysicalBackups, isLoading: isEnabling } = useEnablePhysicalBackupsMutation(+ {+ onSuccess: () => {+ setEnabling(true)+ setRefetchInterval(5000)+ },+ }+ )++ const { mutate: setUpReplica } = useReadReplicaSetUpMutation({+ onSuccess: () => {+ const region = AVAILABLE_REPLICA_REGIONS.find((r) => r.key === selectedRegion)?.name+ toast.success(`Spinning up new replica in ${region ?? ' Unknown'}...`)+ setOpen(false)+ },+ onError: (error) => {+ setEnabling(false)+ toast.error(`Failed to deploy relica: ${error.message}`)+ },+ })++ return (+ <Dialog open={open} onOpenChange={setOpen}>+ <DialogTrigger asChild>+ <Button type="primary">Deploy replica</Button>+ </DialogTrigger>+ <DialogContent>+ <DialogHeader>+ <DialogTitle>Physical backups are required to deploy replicas</DialogTitle>+ <DialogDescription>+ They are used under the hood to spin up read replicas for your project+ </DialogDescription>+ </DialogHeader>+ <DialogSectionSeparator />+ <DialogSection className="flex flex-col gap-y-2">+ {enabling ? (+ <>+ <div className="flex items-center gap-x-3">+ <Loader2 className="animate-spin" size={16} />+ <p className="text-sm">Enabling physical backups</p>+ </div>+ <Markdown+ content={`Please do not close the browser until this is completed. This will take a few minutes and your read replica will be deployed thereafter.`}+ />+ </>+ ) : (+ <>+ <p className="text-sm">+ Enabling physical backups will take a few minutes, after which your replica will be+ deployed once completed.+ </p>+ <Markdown+ content={`Do note that you will no longer be able to download your [scheduled backups](/projects/${ref}/database/backups/scheduled) once physical backups have been enabled for your project.`}+ />+ </>+ )}+ </DialogSection>+ {!enabling && (+ <DialogFooter>+ <Button asChild type="default" icon={<ExternalLink size={14} />}>+ <a+ target="_blank"+ rel="noreferrer"+ href="https://supabase.com/docs/guides/platform/read-replicas#how-are-read-replicas-made"+ >+ Documentation+ </a>+ </Button>+ <Button+ type="primary"+ loading={isEnabling}+ onClick={() => {+ if (ref) enablePhysicalBackups({ ref })+ }}+ >+ Enable physical backups+ </Button>+ </DialogFooter>+ )}+ </DialogContent>+ </Dialog>+ )+}