Home / Function/ ReadReplicaEligibilityWarnings() — supabase Function Reference

ReadReplicaEligibilityWarnings() — supabase Function Reference

Architecture documentation for the ReadReplicaEligibilityWarnings() function in ReadReplicaEligibilityWarnings.tsx from the supabase codebase.

Entity Profile

Dependency Diagram

graph TD
  48c9b31e_4f0e_ccce_ac00_b4e543e0a71b["ReadReplicaEligibilityWarnings()"]
  f33b16c5_17b4_f52d_2246_269ccf0dc85f["useCheckEligibilityDeployReplica()"]
  48c9b31e_4f0e_ccce_ac00_b4e543e0a71b -->|calls| f33b16c5_17b4_f52d_2246_269ccf0dc85f
  style 48c9b31e_4f0e_ccce_ac00_b4e543e0a71b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/studio/components/interfaces/Database/Replication/DestinationPanel/ReadReplicaForm/ReadReplicaEligibilityWarnings.tsx lines 20–247

export const ReadReplicaEligibilityWarnings = () => {
  const { ref: projectRef } = useParams()
  const { data: org } = useSelectedOrganizationQuery()
  const { data: project } = useSelectedProjectQuery()

  const [refetchInterval, setRefetchInterval] = useState<number | false>(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 (
      <Admonition type="warning" title="Your organization has overdue invoices">
        <p>Please resolve all outstanding invoices first before deploying a new read replica</p>
        <Button asChild type="default" className="mt-2">
          <Link href={`/org/${org?.slug}/billing#invoices`}>View invoices</Link>
        </Button>
      </Admonition>
    )
  }

  if (!isAWSProvider) {
    return (
      <Admonition
        type="warning"
        title="Read replicas are only supported for projects provisioned via AWS"
      >
        <p>
          Projects provisioned by other cloud providers currently will not be able to use read
          replicas
        </p>
        <DocsButton
          abbrev={false}
          className="mt-2"
          href={`${DOCS_URL}/guides/platform/read-replicas#prerequisites`}
        />
      </Admonition>
    )
  }

  if (isAwsK8s) {
    return (
      <Admonition
        type="warning"
        title="Read replicas are not supported for AWS (Revamped) projects"
        description="Projects provisioned by other cloud providers currently will not be able to use read replicas"
      />
    )
  }

  if (isPgVersionBelow15) {
    return (
      <Admonition
        type="warning"
        title="Read replicas can only be deployed with projects on Postgres version 15 and above"
      >
        <p>If you'd like to use read replicas, please contact us via support</p>
        <Button asChild type="default" className="mt-2">
          <SupportLink
            queryParams={{
              projectRef,
              category: SupportCategories.SALES_ENQUIRY,
              subject: 'Enquiry on read replicas',
              message: `Project DB version: ${project?.dbVersion}`,
            }}
          >
            Contact support
          </SupportLink>
        </Button>
      </Admonition>
    )
  }

  if (isBelowSmallCompute) {
    return (
      <Admonition type="warning" title="Project required to at least be on a Small compute">
        <p>
          This is to ensure that read replicas can keep up with the primary databases' activities.
        </p>
        <div className="flex items-center gap-x-2 mt-2">
          <UpgradePlanButton
            variant="default"
            plan="Pro"
            addon="computeSize"
            source="read-replicas"
            featureProposition="deploy Read Replicas"
          >
            Change compute size
          </UpgradePlanButton>
          <DocsButton href={`${DOCS_URL}/guides/platform/read-replicas#prerequisites`} />
        </div>
      </Admonition>
    )
  }

  if (isWalgNotEnabled) {
    return (
      <Admonition
        type="warning"
        title={
          refetchInterval === false
            ? 'Physical backups are required to deploy replicas'
            : 'Physical backups are currently being enabled'
        }
      >
        {refetchInterval === false ? (
          <>
            <p>
              Physical backups are used under the hood to spin up read replicas for your project.
            </p>
            <p>
              Enabling physical backups will take a few minutes, after which you will be able to
              deploy read replicas.
            </p>
          </>
        ) : (
          <>
            <p>
              This warning will go away once physical backups have been enabled - check back in a
              few minutes!
            </p>
            <p>You may start deploying read replicas thereafter once this is completed.</p>
          </>
        )}
        {refetchInterval === false && (
          <div className="flex items-center gap-x-2 mt-2">
            <Button
              type="default"
              loading={isEnabling}
              disabled={isEnabling}
              onClick={() => {
                if (projectRef) enablePhysicalBackups({ ref: projectRef })
              }}
            >
              Enable physical backups
            </Button>
            <DocsButton
              abbrev={false}
              href={`${DOCS_URL}/guides/platform/read-replicas#how-are-read-replicas-made`}
            />
          </div>
        )}
      </Admonition>
    )
  }

  if (isProWithSpendCapEnabled) {
    return (
      <Admonition type="warning" title="Spend cap needs to be disabled to deploy replicas">
        <p>
          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.
        </p>
        <UpgradePlanButton
          variant="default"
          source="read-replicas"
          addon="spendCap"
          className="mt-2"
        />
      </Admonition>
    )
  }

  if (isReachedMaxReplicas) {
    return (
      <Admonition
        type="warning"
        title={`You can only deploy up to ${maxNumberOfReplicas} read replicas at once`}
      >
        <p>If you'd like to spin up another read replica, please drop an existing replica first.</p>
        {maxNumberOfReplicas === MAX_REPLICAS_BELOW_XL && (
          <>
            <p>
              Alternatively, you may deploy up to{' '}
              <span className="text-foreground">{MAX_REPLICAS_ABOVE_XL}</span> replicas if your
              project is on an XL compute or higher.
            </p>
            <UpgradePlanButton
              variant="default"
              plan="Pro"
              addon="computeSize"
              source="read-replicas"
              featureProposition="deploy Read Replicas"
              className="mt-2"
            >
              Change compute size
            </UpgradePlanButton>
          </>
        )}
      </Admonition>
    )
  }
}

Subdomains

Frequently Asked Questions

What does ReadReplicaEligibilityWarnings() do?
ReadReplicaEligibilityWarnings() is a function in the supabase codebase.
What does ReadReplicaEligibilityWarnings() call?
ReadReplicaEligibilityWarnings() calls 1 function(s): useCheckEligibilityDeployReplica.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free