Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

3.1 KB
Raw Blame
export interface IPv4DisabledReasonOptions {
  isAws: boolean
  isProjectActive: boolean
  projectUpdateDisabled: boolean
  canUpdateIPv4: boolean
  ipv4Enabled: boolean
  isHighAvailability: boolean
}

export const getIPv4DisabledReason = ({
  isAws,
  isProjectActive,
  projectUpdateDisabled,
  canUpdateIPv4,
  ipv4Enabled,
  isHighAvailability,
}: IPv4DisabledReasonOptions) => {
  if (isHighAvailability) {
    return 'Dedicated IPv4 address is unavailable on High Availability projects'
  }

  if (!isAws) {
    return 'Dedicated IPv4 address is only available for AWS projects'
  }

  if (!isProjectActive) {
    return 'Project must be active to update IPv4'
  }

  if (projectUpdateDisabled) {
    return 'Project updates are currently disabled'
  }

  if (!canUpdateIPv4 && !ipv4Enabled) {
    return 'You can only add IPv4 when your project network configuration is set to IPv6'
  }

  return undefined
}

export interface PitrDisabledReasonOptions {
  isProjectActive: boolean
  projectUpdateDisabled: boolean
  hasHipaaAddon: boolean
  sufficientPgVersion: boolean
  isOrioleDbInAws: boolean
  isHighAvailability: boolean
}

export const getPitrDisabledReason = ({
  isProjectActive,
  projectUpdateDisabled,
  hasHipaaAddon,
  sufficientPgVersion,
  isOrioleDbInAws,
  isHighAvailability,
}: PitrDisabledReasonOptions) => {
  if (isHighAvailability) {
    return 'Point in time recovery is unavailable on High Availability projects'
  }

  if (!isProjectActive) {
    return 'Project must be active to update PITR'
  }

  if (projectUpdateDisabled) {
    return 'Project updates are currently disabled'
  }

  if (hasHipaaAddon) {
    return 'PITR cannot be changed with HIPAA enabled'
  }

  if (!sufficientPgVersion) {
    return 'Your project is too old to enable PITR'
  }

  if (isOrioleDbInAws) {
    return 'Point in time recovery is not supported with OrioleDB'
  }

  return undefined
}

export interface CustomDomainDisabledReasonOptions {
  isProjectActive: boolean
  projectUpdateDisabled: boolean
  isHighAvailability: boolean
}

export const getCustomDomainDisabledReason = ({
  isProjectActive,
  projectUpdateDisabled,
  isHighAvailability,
}: CustomDomainDisabledReasonOptions) => {
  if (isHighAvailability) {
    return 'Custom domain is unavailable on High Availability projects'
  }

  if (!isProjectActive) {
    return 'Project must be active to update custom domain'
  }

  if (projectUpdateDisabled) {
    return 'Project updates are currently disabled'
  }

  return undefined
}

export type PitrAlertState =
  | 'hipaa'
  | 'hipaa-non-compliant'
  | 'legacy-project'
  | 'orioledb'
  | undefined

export const getPitrAlertState = ({
  hasHipaaAddon,
  hasHipaaCompliantPitr = true,
  sufficientPgVersion,
  isOrioleDbInAws,
}: Pick<PitrDisabledReasonOptions, 'hasHipaaAddon' | 'sufficientPgVersion' | 'isOrioleDbInAws'> & {
  hasHipaaCompliantPitr?: boolean
}): PitrAlertState => {
  if (hasHipaaAddon) {
    return hasHipaaCompliantPitr ? 'hipaa' : 'hipaa-non-compliant'
  }

  if (!sufficientPgVersion) {
    return 'legacy-project'
  }

  if (isOrioleDbInAws) {
    return 'orioledb'
  }

  return undefined
}