Home / Function/ useCheckEligibilityDeployReplica() — supabase Function Reference

useCheckEligibilityDeployReplica() — supabase Function Reference

Architecture documentation for the useCheckEligibilityDeployReplica() function in useCheckEligibilityDeployReplica.ts from the supabase codebase.

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

apps/studio/components/interfaces/Database/Replication/DestinationPanel/ReadReplicaForm/useCheckEligibilityDeployReplica.ts lines 15–83

export const useCheckEligibilityDeployReplica = () => {
  const { ref: projectRef } = useParams()
  const isAwsK8s = useIsAwsK8sCloudProvider()
  const { data: project } = useSelectedProjectQuery()
  const { data: org } = useSelectedOrganizationQuery()
  const { hasAccess: hasReadReplicaAccess } = useCheckEntitlements('instances.read_replicas')
  const isAWSProvider = project?.cloud_provider === 'AWS'
  const isWalgEnabled = project?.is_physical_backups_enabled
  const isNotOnHigherPlan = useMemo(
    () => !['team', 'enterprise', 'platform'].includes(org?.plan.id ?? ''),
    [org]
  )
  const isProWithSpendCapEnabled = org?.plan.id === 'pro' && !org.usage_billing_enabled

  const { data: allOverdueInvoices } = useOverdueInvoicesQuery({
    enabled: isNotOnHigherPlan,
  })
  const overdueInvoices = (allOverdueInvoices ?? []).filter(
    (x) => x.organization_id === project?.organization_id
  )
  const hasOverdueInvoices = overdueInvoices.length > 0 && isNotOnHigherPlan

  const { data: databases = [] } = useReadReplicasQuery({ projectRef })

  const { data: addons } = useProjectAddonsQuery({ projectRef })
  // Will be following the primary's compute size for the time being
  const currentComputeAddon = addons?.selected_addons.find(
    (addon) => addon.type === 'compute_instance'
  )?.variant.identifier
  const isMinimallyOnSmallCompute =
    currentComputeAddon !== undefined && currentComputeAddon !== 'ci_micro'

  const maxNumberOfReplicas = ['ci_micro', 'ci_small', 'ci_medium', 'ci_large'].includes(
    currentComputeAddon ?? 'ci_micro'
  )
    ? MAX_REPLICAS_BELOW_XL
    : MAX_REPLICAS_ABOVE_XL
  const isReachedMaxReplicas =
    (databases ?? []).filter((db) => db.identifier !== projectRef).length >= maxNumberOfReplicas

  const currentPgVersion = Number(
    (project?.dbVersion ?? '').split('supabase-postgres-')[1]?.split('.')[0]
  )

  const canDeployReplica =
    !isReachedMaxReplicas &&
    currentPgVersion >= 15 &&
    isAWSProvider &&
    hasReadReplicaAccess &&
    isWalgEnabled &&
    currentComputeAddon !== undefined &&
    !hasOverdueInvoices &&
    !isAwsK8s &&
    !isProWithSpendCapEnabled &&
    isMinimallyOnSmallCompute

  return {
    can: canDeployReplica,
    hasOverdueInvoices,
    isAWSProvider,
    isAwsK8s,
    isPgVersionBelow15: currentPgVersion < 15,
    isBelowSmallCompute: !isMinimallyOnSmallCompute,
    isWalgNotEnabled: !isWalgEnabled,
    isProWithSpendCapEnabled,
    isReachedMaxReplicas,
    maxNumberOfReplicas,
  }
}

Subdomains

Frequently Asked Questions

What does useCheckEligibilityDeployReplica() do?
useCheckEligibilityDeployReplica() is a function in the supabase codebase.
What calls useCheckEligibilityDeployReplica()?
useCheckEligibilityDeployReplica() is called by 2 function(s): ReadReplicaEligibilityWarnings, ReadReplicaForm.

Analyze Your Own Codebase

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

Try Supermodel Free