import { SupportCategories } from '@supabase/shared-types/out/constants' import { useParams } from 'common' import Link from 'next/link' import { useEffect, useState } from 'react' import { toast } from 'sonner' import { Button } from 'ui' import { Admonition } from 'ui-patterns' import { useCheckEligibilityDeployReplica } from './useCheckEligibilityDeployReplica' import { SupportLink } from '@/components/interfaces/Support/SupportLink' import { DocsButton } from '@/components/ui/DocsButton' import { UpgradePlanButton } from '@/components/ui/UpgradePlanButton' import { useEnablePhysicalBackupsMutation } from '@/data/database/enable-physical-backups-mutation' import { useProjectDetailQuery } from '@/data/projects/project-detail-query' import { READ_REPLICAS_MAX_COUNT } from '@/data/read-replicas/replicas-query' import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization' import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject' import { DOCS_URL } from '@/lib/constants' export const ReadReplicaEligibilityWarnings = () => { const { ref: projectRef } = useParams() const { data: org } = useSelectedOrganizationQuery() const { data: project } = useSelectedProjectQuery() const [refetchInterval, setRefetchInterval] = useState(false) const { hasOverdueInvoices, isAWSProvider, isAwsK8s, isPgVersionBelow15, isBelowSmallCompute, isWalgNotEnabled, isProWithSpendCapEnabled, isReachedMaxReplicas, maxNumberOfReplicas, } = useCheckEligibilityDeployReplica() const { data: projectDetail, isSuccess: isProjectDetailSuccess } = useProjectDetailQuery( { ref: projectRef }, { refetchInterval, refetchOnWindowFocus: false, } ) const { mutate: enablePhysicalBackups, isPending: isEnabling } = useEnablePhysicalBackupsMutation( { onSuccess: () => { toast.success( 'Physical backups are currently being enabled, please check back in a few minutes!' ) setRefetchInterval(5000) }, } ) useEffect(() => { if (!isProjectDetailSuccess) return if (projectDetail.is_physical_backups_enabled) { setRefetchInterval(false) } }, [projectDetail?.is_physical_backups_enabled, isProjectDetailSuccess]) if (hasOverdueInvoices) { return (

Please resolve all outstanding invoices first before deploying a new read replica

) } if (!isAWSProvider) { return (

Projects provisioned by other cloud providers currently will not be able to use read replicas

) } if (isAwsK8s) { return ( ) } if (isPgVersionBelow15) { return (

If you'd like to use read replicas, please contact us via support

) } if (isBelowSmallCompute) { return (

This is to ensure that read replicas can keep up with the primary databases' activities.

) } if (isWalgNotEnabled) { return ( {refetchInterval === false ? ( <>

Physical backups are used under the hood to spin up read replicas for your project.

Enabling physical backups will take a few minutes, after which you will be able to deploy read replicas.

) : ( <>

This warning will go away once physical backups have been enabled - check back in a few minutes!

You may start deploying read replicas thereafter once this is completed.

)} {refetchInterval === false && (
)}
) } if (isProWithSpendCapEnabled) { return (

Launching a replica incurs additional disk size that will exceed the plan's quota. Disable the spend cap first to allow overages before launching a replica.

Disable spend cap
) } if (isReachedMaxReplicas) { return (

If you'd like to spin up another read replica, please drop an existing replica first.

{maxNumberOfReplicas < READ_REPLICAS_MAX_COUNT && ( <>

Alternatively, you may deploy up to{' '} {READ_REPLICAS_MAX_COUNT} replicas if your project is on an XL compute or higher.

Change compute size )}
) } }