Skip to content

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

Chore/read replica fixes 260224 (#21547)

Joshen Lim3e3017294643
diff --git a/apps/studio/components/interfaces/Database/Backups/PITR/PITRStatus.tsx b/apps/studio/components/interfaces/Database/Backups/PITR/PITRStatus.tsx
index 4b083ad80f0..5d13dee4588 100644
--- a/apps/studio/components/interfaces/Database/Backups/PITR/PITRStatus.tsx
+++ b/apps/studio/components/interfaces/Database/Backups/PITR/PITRStatus.tsx
@@ -61,6 +61,7 @@ const PITRStatus = ({
</div>
<Tooltip.Root delayDuration={0}>
<Tooltip.Trigger asChild>
+ {/* [Joshen TODO] Double check if this is intentional */}
<Button
disabled={hasReadReplicas || !canTriggerPhysicalBackup}
onClick={() => onSetConfiguration()}
@@ -68,23 +69,28 @@ const PITRStatus = ({
Start a restore
</Button>
</Tooltip.Trigger>
- {!canTriggerPhysicalBackup && (
- <Tooltip.Portal>
- <Tooltip.Content side="left">
- <Tooltip.Arrow className="radix-tooltip-arrow" />
- <div
- className={[
- 'rounded bg-alternative py-1 px-2 leading-none shadow',
- 'border border-background',
- ].join(' ')}
- >
- <span className="text-xs text-foreground">
- You need additional permissions to trigger a PITR recovery
- </span>
- </div>
- </Tooltip.Content>
- </Tooltip.Portal>
- )}
+ {hasReadReplicas ||
+ (!canTriggerPhysicalBackup && (
+ <Tooltip.Portal>
+ <Tooltip.Content side="left">
+ <Tooltip.Arrow className="radix-tooltip-arrow" />
+ <div
+ className={[
+ 'rounded bg-alternative py-1 px-2 leading-none shadow',
+ 'border border-background',
+ ].join(' ')}
+ >
+ <span className="text-xs text-foreground">
+ {hasReadReplicas
+ ? 'You will need to remove all read replicas first to trigger a PITR recovery'
+ : !canTriggerPhysicalBackup
+ ? 'You need additional permissions to trigger a PITR recovery'
+ : null}
+ </span>
+ </div>
+ </Tooltip.Content>
+ </Tooltip.Portal>
+ ))}
</Tooltip.Root>
</div>
}
diff --git a/apps/studio/components/interfaces/Settings/Addons/ComputeInstanceSidePanel.tsx b/apps/studio/components/interfaces/Settings/Addons/ComputeInstanceSidePanel.tsx
index 5771f56abc6..991f0f5477d 100644
--- a/apps/studio/components/interfaces/Settings/Addons/ComputeInstanceSidePanel.tsx
+++ b/apps/studio/components/interfaces/Settings/Addons/ComputeInstanceSidePanel.tsx
@@ -35,6 +35,8 @@ import {
import * as Tooltip from '@radix-ui/react-tooltip'
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
import { AddonVariantId, ProjectAddonVariantMeta } from 'data/subscriptions/types'
+import { useReadReplicasQuery } from 'data/read-replicas/replicas-query'
+import { WarningIcon } from 'components/ui/Icons'
const ComputeInstanceSidePanel = () => {
const queryClient = useQueryClient()
@@ -61,6 +63,7 @@ const ComputeInstanceSidePanel = () => {
snap.setPanelKey(undefined)
}
+ const { data: databases } = useReadReplicasQuery({ projectRef })
const { data: addons, isLoading } = useProjectAddonsQuery({ projectRef })
const { data: subscription } = useOrgSubscriptionQuery({ orgSlug: organization?.slug })
const { mutate: updateAddon, isLoading: isUpdating } = useProjectAddonUpdateMutation({
@@ -105,7 +108,6 @@ const ComputeInstanceSidePanel = () => {
const [selectedOption, setSelectedOption] = useState<string>('')
const isSubmitting = isUpdating || isRemoving
-
const projectId = selectedProject?.id
const cpuArchitecture = getCloudProviderArchitecture(selectedProject?.cloud_provider)
const selectedAddons = addons?.selected_addons ?? []
@@ -162,9 +164,12 @@ const ComputeInstanceSidePanel = () => {
const selectedCompute = availableOptions.find((option) => option.identifier === selectedOption)
const hasChanges =
selectedOption !== (subscriptionCompute?.variant.identifier ?? defaultInstanceSize)
+ const hasReadReplicas = (databases ?? []).length > 1
const blockDowngradeDueToPitr =
pitrAddon !== undefined && ['ci_micro', 'ci_nano'].includes(selectedOption) && hasChanges
+ const blockDowngradeDueToReadReplicas =
+ hasChanges && hasReadReplicas && ['ci_micro', 'ci_nano'].includes(selectedOption)
useEffect(() => {
if (visible) {
@@ -217,7 +222,12 @@ const ComputeInstanceSidePanel = () => {
onConfirm={() => setShowConfirmationModal(true)}
loading={isLoading}
disabled={
- isFreePlan || isLoading || !hasChanges || blockDowngradeDueToPitr || !canUpdateCompute
+ isFreePlan ||
+ isLoading ||
+ !hasChanges ||
+ blockDowngradeDueToPitr ||
+ blockDowngradeDueToReadReplicas ||
+ !canUpdateCompute
}
tooltip={
isFreePlan
@@ -382,38 +392,66 @@ const ComputeInstanceSidePanel = () => {
</p>
)}
- {hasChanges && !blockDowngradeDueToPitr && (
- <Alert
- withIcon
- variant="info"
- title="Your project will need to be restarted when changing it's compute size"
- >
- Your project will be unavailable for up to 2 minutes while the changes take place.
- </Alert>
+ {hasChanges && !blockDowngradeDueToPitr && !blockDowngradeDueToReadReplicas && (
+ <Alert_Shadcn_>
+ <WarningIcon />
+ <AlertTitle_Shadcn_>
+ Your project will need to be restarted when changing it's compute size
+ </AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>
+ Your project will be unavailable for up to 2 minutes while the changes take place.
+ </AlertDescription_Shadcn_>
+ {hasReadReplicas && (
+ <AlertDescription_Shadcn_>
+ The compute sizes for <span className="text-foreground">all read replicas</span>{' '}
+ on your project will also be changed to the {selectedCompute?.name} size as
+ well.
+ </AlertDescription_Shadcn_>
+ )}
+ </Alert_Shadcn_>
)}
- {blockDowngradeDueToPitr && (
- <Alert
- withIcon
- variant="info"
- className="mb-4"
- title="Disable PITR before downgrading"
- actions={
- <Button type="default" onClick={() => snap.setPanelKey('pitr')}>
- Change PITR
+ {blockDowngradeDueToReadReplicas ? (
+ <Alert_Shadcn_>
+ <WarningIcon />
+ <AlertTitle_Shadcn_>
+ Unable to downgrade as project has active read replicas
+ </AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>
+ The minimum compute instance size for using read replicas is the Small Compute.
+ You need to remove all read replicas before downgrading Compute as it requires at
+ least a Small compute instance.
+ </AlertDescription_Shadcn_>
+ <AlertDescription_Shadcn_ className="mt-2">
+ <Button asChild type="default">
+ <Link
+ href={`/project/${projectRef}/settings/infrastructure`}
+ onClick={() => snap.setPanelKey(undefined)}
+ >
+ Manage read replicas
+ </Link>
</Button>
- }
- >
- <p>
+ </AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
+ ) : blockDowngradeDueToPitr ? (
+ <Alert_Shadcn_>
+ <WarningIcon />
+ <AlertTitle_Shadcn_>Disable PITR before downgrading</AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>
You currently have PITR enabled. The minimum compute instance size for using PITR
is the Small Compute.
- </p>
- <p>
+ </AlertDescription_Shadcn_>
+ <AlertDescription_Shadcn_>
You need to disable PITR before downgrading Compute as it requires at least a
Small compute instance.
- </p>
- </Alert>
- )}
+ </AlertDescription_Shadcn_>
+ <AlertDescription_Shadcn_ className="mt-2">
+ <Button type="default" onClick={() => snap.setPanelKey('pitr')}>
+ Change PITR
+ </Button>
+ </AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
+ ) : null}
{hasChanges &&
subscription?.billing_via_partner &&
diff --git a/apps/studio/components/interfaces/Settings/Addons/PITRSidePanel.tsx b/apps/studio/components/interfaces/Settings/Addons/PITRSidePanel.tsx
index e539aa53a37..70a052fa4d0 100644
--- a/apps/studio/components/interfaces/Settings/Addons/PITRSidePanel.tsx
+++ b/apps/studio/components/interfaces/Settings/Addons/PITRSidePanel.tsx
@@ -5,14 +5,20 @@ import { useRouter } from 'next/router'
import { useEffect, useState } from 'react'
import { useParams } from 'common'
-import { useTheme } from 'next-themes'
import { useProjectAddonRemoveMutation } from 'data/subscriptions/project-addon-remove-mutation'
import { useProjectAddonUpdateMutation } from 'data/subscriptions/project-addon-update-mutation'
import { useProjectAddonsQuery } from 'data/subscriptions/project-addons-query'
import { useCheckPermissions, useSelectedOrganization, useSelectedProject, useStore } from 'hooks'
import { BASE_PATH } from 'lib/constants'
import Telemetry from 'lib/telemetry'
+import { useTheme } from 'next-themes'
+import { subscriptionHasHipaaAddon } from 'components/interfaces/Billing/Subscription/Subscription.utils'
+import { CriticalIcon, WarningIcon } from 'components/ui/Icons'
+import { useReadReplicasQuery } from 'data/read-replicas/replicas-query'
+import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
+import { AddonVariantId } from 'data/subscriptions/types'
+import { formatCurrency } from 'lib/helpers'
import { useSubscriptionPageStateSnapshot } from 'state/subscription-page'
import {
Alert,
@@ -20,16 +26,11 @@ import {
AlertTitle_Shadcn_,
Alert_Shadcn_,
Button,
+ IconAlertTriangle,
IconExternalLink,
Radio,
SidePanel,
- IconAlertTriangle,
} from 'ui'
-import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
-import { AlertTriangleIcon } from 'lucide-react'
-import { AddonVariantId } from 'data/subscriptions/types'
-import { subscriptionHasHipaaAddon } from 'components/interfaces/Billing/Subscription/Subscription.utils'
-import { formatCurrency } from 'lib/helpers'
const PITR_CATEGORY_OPTIONS: {
id: 'off' | 'on'
@@ -76,6 +77,7 @@ const PITRSidePanel = () => {
snap.setPanelKey(undefined)
}
+ const { data: databases } = useReadReplicasQuery({ projectRef })
const { data: addons, isLoading } = useProjectAddonsQuery({ projectRef })
const { data: subscription } = useOrgSubscriptionQuery({ orgSlug: organization?.slug })
const hasHipaaAddon = subscriptionHasHipaaAddon(subscription)
@@ -121,9 +123,12 @@ const PITRSidePanel = () => {
const subscriptionPitr = selectedAddons.find((addon) => addon.type === 'pitr')
const availableOptions = availableAddons.find((addon) => addon.type === 'pitr')?.variants ?? []
+ const hasReadReplicas = (databases ?? []).length > 1
const hasChanges = selectedOption !== (subscriptionPitr?.variant.identifier ?? 'pitr_0')
const selectedPitr = availableOptions.find((option) => option.identifier === selectedOption)
const isFreePlan = subscription?.plan?.id === 'free'
+ const blockDowngradeDueToReadReplicas =
+ hasChanges && hasReadReplicas && selectedCategory === 'off' && selectedOption === 'pitr_0'
useEffect(() => {
if (visible) {
@@ -167,7 +172,13 @@ const PITRSidePanel = () => {
onConfirm={onConfirm}
loading={isLoading || isSubmitting}
disabled={
- isFreePlan || isLoading || !hasChanges || isSubmitting || !canUpdatePitr || hasHipaaAddon
+ isFreePlan ||
+ isLoading ||
+ !hasChanges ||
+ isSubmitting ||
+ !canUpdatePitr ||
+ hasHipaaAddon ||
+ blockDowngradeDueToReadReplicas
}
tooltip={
hasHipaaAddon
@@ -225,7 +236,13 @@ const PITRSidePanel = () => {
className={clsx('col-span-3 group space-y-1', isFreePlan && 'opacity-75')}
onClick={() => {
setSelectedCategory(option.id)
- if (option.id === 'off') setSelectedOption('pitr_0')
+ if (option.id === 'off') {
+ setSelectedOption('pitr_0')
+ } else if (subscriptionPitr?.variant.identifier !== undefined) {
+ setSelectedOption(subscriptionPitr.variant.identifier)
+ } else {
+ setSelectedOption('pitr_7')
+ }
Telemetry.sendActivity(
{
activity: 'Option Selected',
@@ -270,7 +287,7 @@ const PITRSidePanel = () => {
{selectedCategory === 'off' && subscriptionPitr !== undefined && isBranchingEnabled && (
<Alert_Shadcn_ variant="warning">
- <AlertTriangleIcon strokeWidth={2} />
+ <CriticalIcon />
<AlertTitle_Shadcn_>
Are you sure you want to disable this while using Branching?
</AlertTitle_Shadcn_>
@@ -281,6 +298,25 @@ const PITRSidePanel = () => {
</Alert_Shadcn_>
)}
+ {blockDowngradeDueToReadReplicas && (
+ <Alert_Shadcn_>
+ <WarningIcon />
+ <AlertTitle_Shadcn_>Remove all read replicas before downgrading</AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>
+ You currently have active read replicas. The minimum compute instance size for using
+ read replicas is the Small Compute. You need to remove all read replicas before
+ downgrading Compute as it requires at least a Small compute instance.
+ </AlertDescription_Shadcn_>
+ <AlertDescription_Shadcn_ className="mt-2">
+ <Button asChild type="default">
+ <Link href={`/project/${projectRef}/settings/infrastructure`}>
+ Manage read replicas
+ </Link>
+ </Button>
+ </AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
+ )}
+
{selectedCategory === 'on' && (
<div className="!mt-8 pb-4">
{isFreePlan ? (
@@ -358,7 +394,7 @@ const PITRSidePanel = () => {
</div>
)}
- {hasChanges && (
+ {hasChanges && !blockDowngradeDueToReadReplicas && (
<>
{selectedOption === 'pitr_0' ||
(selectedPitr?.price ?? 0) < (subscriptionPitr?.variant.price ?? 0) ? (
diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DeployNewReplicaPanel.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DeployNewReplicaPanel.tsx
index 0faf37c0f5c..34d5447fe2b 100644
--- a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DeployNewReplicaPanel.tsx
+++ b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DeployNewReplicaPanel.tsx
@@ -6,7 +6,6 @@ import {
AlertTitle_Shadcn_,
Alert_Shadcn_,
Button,
- IconAlertCircle,
Listbox,
SidePanel,
} from 'ui'
@@ -20,6 +19,7 @@ import Link from 'next/link'
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
import { useSelectedOrganization, useSelectedProject } from 'hooks'
import { WarningIcon } from 'components/ui/Icons'
+import { getSemanticVersion } from 'lib/helpers'
// [Joshen] FYI this is purely for AWS only, need to update to support Fly eventually
@@ -53,6 +53,10 @@ const DeployNewReplicaPanel = ({
},
})
+ const currentPgVersion = Number(
+ (project?.dbVersion ?? '').split('supabase-postgres-')[1]?.split('.')[0]
+ )
+
const reachedMaxReplicas = (data ?? []).filter((db) => db.identifier !== projectRef).length >= 2
const isFreePlan = subscription?.plan.id === 'free'
const currentComputeAddon = addons?.selected_addons.find(
@@ -61,6 +65,7 @@ const DeployNewReplicaPanel = ({
const currentPitrAddon = addons?.selected_addons.find((addon) => addon.type === 'pitr')
const canDeployReplica =
!reachedMaxReplicas &&
+ currentPgVersion >= 15 &&
project?.cloud_provider === 'AWS' &&
!isFreePlan &&
currentComputeAddon !== undefined &&
@@ -82,6 +87,11 @@ const DeployNewReplicaPanel = ({
const [selectedCompute, setSelectedCompute] = useState(defaultCompute)
const selectedComputeMeta = computeAddons.find((addon) => addon.identifier === selectedCompute)
+ const availableRegions =
+ process.env.NEXT_PUBLIC_ENVIRONMENT === 'staging'
+ ? AVAILABLE_REPLICA_REGIONS.filter((x) => x.key === 'SOUTHEAST_ASIA')
+ : AVAILABLE_REPLICA_REGIONS
+
const onSubmit = async () => {
const regionKey = AWS_REGIONS_VALUES[selectedRegion]
if (!projectRef) return console.error('Project is required')
@@ -162,6 +172,41 @@ const DeployNewReplicaPanel = ({
</AlertDescription_Shadcn_>
</Alert_Shadcn_>
)}
+ {/* [Joshen] Not particular about this warning as all users on prod are on AWS */}
+ {project?.cloud_provider !== 'AWS' && (
+ <Alert_Shadcn_>
+ <WarningIcon />
+ <AlertTitle_Shadcn_>
+ Read replicas can only be deployed with projects on AWS
+ </AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>
+ If you'd like to use read replicas, please migrate your project to AWS by creating a
+ new one.
+ </AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
+ )}
+ {currentPgVersion < 15 && (
+ <Alert_Shadcn_>
+ <WarningIcon />
+ <AlertTitle_Shadcn_>
+ Read replicas can only be deployed with projects on Postgres version 15 and above
+ </AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>
+ If you'd like to use read replicas, please contact us via support
+ </AlertDescription_Shadcn_>
+ <AlertDescription_Shadcn_ className="mt-2">
+ <Button type="default">
+ <Link
+ href={`/support/new?category=Sales&ref=${projectRef}&subject=Enquiry%20on%20read%20replicas&message=Project%20DB%20version:%20${project?.dbVersion}`}
+ target="_blank"
+ rel="noreferrer"
+ >
+ Contact support
+ </Link>
+ </Button>
+ </AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
+ )}
<Listbox
size="small"
id="region"
@@ -171,7 +216,7 @@ const DeployNewReplicaPanel = ({
onChange={setSelectedRegion}
label="Select a region to deploy your read replica in"
>
- {AVAILABLE_REPLICA_REGIONS.map((region) => (
+ {availableRegions.map((region) => (
<Listbox.Option
key={region.key}
label={region.name}
diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DropAllReplicasConfirmationModal.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DropAllReplicasConfirmationModal.tsx
new file mode 100644
index 00000000000..df821f30967
--- /dev/null
+++ b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DropAllReplicasConfirmationModal.tsx
@@ -0,0 +1,91 @@
+import { useParams } from 'common'
+import toast from 'react-hot-toast'
+import {
+ AlertDescription_Shadcn_,
+ AlertTitle_Shadcn_,
+ Alert_Shadcn_,
+ IconAlertTriangle,
+ Modal,
+} from 'ui'
+
+import ConfirmationModal from 'components/ui/ConfirmationModal'
+import { useReadReplicaRemoveMutation } from 'data/read-replicas/replica-remove-mutation'
+import { Database, useReadReplicasQuery } from 'data/read-replicas/replicas-query'
+import { useQueryClient } from '@tanstack/react-query'
+import { replicaKeys } from 'data/read-replicas/keys'
+
+interface DropAllReplicasConfirmationModalProps {
+ visible: boolean
+ onSuccess: () => void
+ onCancel: () => void
+}
+
+const DropAllReplicasConfirmationModal = ({
+ visible,
+ onSuccess,
+ onCancel,
+}: DropAllReplicasConfirmationModalProps) => {
+ const { ref: projectRef } = useParams()
+ const queryClient = useQueryClient()
+ const { data: databases } = useReadReplicasQuery({ projectRef })
+ const { mutateAsync: removeReadReplica, isLoading: isRemoving } = useReadReplicaRemoveMutation()
+
+ const onConfirmRemove = async () => {
+ if (!projectRef) return console.error('Project is required')
+ if (databases === undefined) return console.error('Unable to retrieve replicas')
+ if (databases.length === 1) toast('Your project has no read replicas')
+
+ const replicas = databases.filter((db) => db.identifier !== projectRef)
+ await Promise.all(
+ replicas.map((db) =>
+ removeReadReplica({ projectRef, identifier: db.identifier, skipInvalidateOnSuccess: true })
+ )
+ )
+ toast.success(`Tearing down all read replicas`)
+
+ queryClient.setQueriesData<any>(replicaKeys.list(projectRef), (old: Database[]) => {
+ return old.filter((db: Database) => db.identifier === projectRef)
+ })
+ queryClient.setQueriesData<any>(replicaKeys.loadBalancers(projectRef), (old: Database[]) => [])
+
+ setTimeout(async () => {
+ await queryClient.invalidateQueries(replicaKeys.list(projectRef))
+ await queryClient.invalidateQueries(replicaKeys.loadBalancers(projectRef))
+ }, 5000)
+
+ onSuccess()
+ onCancel()
+ }
+
+ return (
+ <ConfirmationModal
+ danger
+ size="medium"
+ loading={isRemoving}
+ visible={visible}
+ header="Confirm to drop all read replicas?"
+ buttonLabel="Drop all replicas"
+ buttonLoadingLabel="Dropping all replicas"
+ onSelectCancel={() => onCancel()}
+ onSelectConfirm={() => onConfirmRemove()}
+ >
+ <Modal.Content className="py-3">
+ <Alert_Shadcn_ variant="warning">
+ <IconAlertTriangle strokeWidth={2} />
+ <AlertTitle_Shadcn_>This action cannot be undone</AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>
+ You may still deploy new replicas in this region thereafter
+ </AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
+ <div className="text-sm px-1 pt-4">
+ <p>Before deleting all replicas, consider:</p>
+ <ul className="text-foreground-light py-1 list-disc mx-4 space-y-1">
+ <li>Network traffic from this region may slow down</li>
+ </ul>
+ </div>
+ </Modal.Content>
+ </ConfirmationModal>
+ )
+}
+
+export default DropAllReplicasConfirmationModal
diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DropReplicaConfirmationModal.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DropReplicaConfirmationModal.tsx
index ae311a2ef92..319b7f661c8 100644
--- a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DropReplicaConfirmationModal.tsx
+++ b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DropReplicaConfirmationModal.tsx
@@ -26,7 +26,7 @@ const DropReplicaConfirmationModal = ({
}: DropReplicaConfirmationModalProps) => {
const { ref: projectRef } = useParams()
const formattedId = formatDatabaseID(selectedReplica?.identifier ?? '')
- const { mutateAsync: removeReadReplica } = useReadReplicaRemoveMutation({
+ const { mutateAsync: removeReadReplica, isLoading: isRemoving } = useReadReplicaRemoveMutation({
onSuccess: () => {
toast.success(`Tearing down read replica (ID: ${formattedId})`)
onSuccess()
@@ -45,6 +45,7 @@ const DropReplicaConfirmationModal = ({
<ConfirmationModal
danger
size="medium"
+ loading={isRemoving}
visible={selectedReplica !== undefined}
header={`Confirm to drop selected replica? (ID: ${formattedId})`}
buttonLabel="Drop replica"
diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration.tsx
index a878354fdc8..f68593424aa 100644
--- a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration.tsx
+++ b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration.tsx
@@ -5,7 +5,15 @@ import { useTheme } from 'next-themes'
import { useEffect, useMemo, useRef, useState } from 'react'
import ReactFlow, { Background, Edge, ReactFlowProvider, useReactFlow } from 'reactflow'
import 'reactflow/dist/style.css'
-import { Button } from 'ui'
+import {
+ Button,
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
+ IconChevronDown,
+} from 'ui'
import AlertError from 'components/ui/AlertError'
import { useLoadBalancersQuery } from 'data/read-replicas/load-balancers-query'
@@ -13,11 +21,14 @@ import { Database, useReadReplicasQuery } from 'data/read-replicas/replicas-quer
import { useReadReplicasStatusesQuery } from 'data/read-replicas/replicas-status-query'
import { AWS_REGIONS_KEYS } from 'lib/constants'
import { timeout } from 'lib/helpers'
+import { useSubscriptionPageStateSnapshot } from 'state/subscription-page'
+import ComputeInstanceSidePanel from '../../Addons/ComputeInstanceSidePanel'
import DeployNewReplicaPanel from './DeployNewReplicaPanel'
import DropReplicaConfirmationModal from './DropReplicaConfirmationModal'
import { addRegionNodes, generateNodes, getDagreGraphLayout } from './InstanceConfiguration.utils'
import { LoadBalancerNode, PrimaryNode, RegionNode, ReplicaNode } from './InstanceNode'
import MapView from './MapView'
+import DropAllReplicasConfirmationModal from './DropAllReplicasConfirmationModal'
// [Joshen] Just FYI, UI assumes single provider for primary + replicas
// [Joshen] Idea to visualize grouping based on region: https://reactflow.dev/examples/layout/sub-flows
@@ -28,12 +39,13 @@ const InstanceConfigurationUI = () => {
const { resolvedTheme } = useTheme()
const { ref: projectRef } = useParams()
const numComingUp = useRef<number>()
+ const snap = useSubscriptionPageStateSnapshot()
const [view, setView] = useState<'flow' | 'map'>('flow')
+ const [showDeleteAllModal, setShowDeleteAllModal] = useState(false)
const [showNewReplicaPanel, setShowNewReplicaPanel] = useState(false)
const [refetchInterval, setRefetchInterval] = useState<number | boolean>(10000)
const [newReplicaRegion, setNewReplicaRegion] = useState<AWS_REGIONS_KEYS>()
- const [selectedReplicaToResize, setSelectedReplicaToResize] = useState<Database>()
const [selectedReplicaToDrop, setSelectedReplicaToDrop] = useState<Database>()
const [selectedReplicaToRestart, setSelectedReplicaToRestart] = useState<Database>()
@@ -86,7 +98,6 @@ const InstanceConfigurationUI = () => {
isSuccessReplicas && isSuccessLoadBalancers
? generateNodes(primary, replicas, loadBalancers ?? [], {
onSelectRestartReplica: setSelectedReplicaToRestart,
- onSelectResizeReplica: setSelectedReplicaToResize,
onSelectDropReplica: setSelectedReplicaToDrop,
})
: [],
@@ -134,10 +145,6 @@ const InstanceConfigurationUI = () => {
[]
)
- const onConfirmRestartReplica = () => {
- console.log('Restart replica', selectedReplicaToRestart)
- }
-
const setReactFlow = async () => {
const graph = getDagreGraphLayout(nodes, edges)
const { nodes: updatedNodes } = addRegionNodes(graph.nodes, graph.edges)
@@ -168,9 +175,33 @@ const InstanceConfigurationUI = () => {
{isSuccessReplicas && (
<>
<div className="z-10 absolute top-4 right-4 flex items-center justify-center gap-x-2">
- <Button type="default" onClick={() => setShowNewReplicaPanel(true)}>
- Deploy a new replica
- </Button>
+ <div className="flex items-center justify-center">
+ <Button
+ type="default"
+ className="rounded-r-none"
+ onClick={() => setShowNewReplicaPanel(true)}
+ >
+ Deploy a new replica
+ </Button>
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button
+ type="default"
+ icon={<IconChevronDown size={16} />}
+ className="px-1 rounded-l-none border-l-0"
+ />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end" className="w-52 *:space-x-2">
+ <DropdownMenuItem onClick={() => snap.setPanelKey('computeInstance')}>
+ <div>Resize databases</div>
+ </DropdownMenuItem>
+ <DropdownMenuSeparator />
+ <DropdownMenuItem onClick={() => setShowDeleteAllModal(true)}>
+ <div>Remove all replicas</div>
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </div>
<div className="flex items-center justify-center">
<Button
type="default"
@@ -215,8 +246,6 @@ const InstanceConfigurationUI = () => {
setNewReplicaRegion(region)
setShowNewReplicaPanel(true)
}}
- onSelectRestartReplica={setSelectedReplicaToRestart}
- onSelectResizeReplica={setSelectedReplicaToResize}
onSelectDropReplica={setSelectedReplicaToDrop}
/>
)}
@@ -240,11 +269,13 @@ const InstanceConfigurationUI = () => {
onCancel={() => setSelectedReplicaToDrop(undefined)}
/>
- {/* <ResizeReplicaPanel
- visible={selectedReplicaToResize !== undefined}
- selectedReplica={selectedReplicaToResize}
- onClose={() => setSelectedReplicaToResize(undefined)}
- /> */}
+ <DropAllReplicasConfirmationModal
+ visible={showDeleteAllModal}
+ onSuccess={() => setRefetchInterval(10000)}
+ onCancel={() => setShowDeleteAllModal(false)}
+ />
+
+ <ComputeInstanceSidePanel />
{/* <ConfirmationModal
size="medium"
diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration.utils.ts b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration.utils.ts
index a521f23e0fb..c7a4ab2e687 100644
--- a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration.utils.ts
+++ b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration.utils.ts
@@ -20,11 +20,9 @@ export const generateNodes = (
loadBalancers: LoadBalancer[],
{
onSelectRestartReplica,
- onSelectResizeReplica,
onSelectDropReplica,
}: {
onSelectRestartReplica: (database: Database) => void
- onSelectResizeReplica: (database: Database) => void
onSelectDropReplica: (database: Database) => void
}
): Node[] => {
@@ -88,7 +86,6 @@ export const generateNodes = (
computeSize: database.size,
status: database.status,
onSelectRestartReplica: () => onSelectRestartReplica(database),
- onSelectResizeReplica: () => onSelectResizeReplica(database),
onSelectDropReplica: () => onSelectDropReplica(database),
},
}
diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceNode.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceNode.tsx
index ba3e04c9e7a..9c901748547 100644
--- a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceNode.tsx
+++ b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceNode.tsx
@@ -214,18 +214,21 @@ export const ReplicaNode = ({ data }: NodeProps<ReplicaNodeData>) => {
<Button type="text" icon={<IconMoreVertical />} className="px-1" />
</DropdownMenuTrigger>
<DropdownMenuContent className="w-40" side="bottom" align="end">
- <DropdownMenuItem className="gap-x-2">
+ <DropdownMenuItem
+ disabled={status !== PROJECT_STATUS.ACTIVE_HEALTHY}
+ className="gap-x-2"
+ >
<Link href={`/project/${ref}/settings/database?connectionString=${id}`}>
View connection string
</Link>
</DropdownMenuItem>
+ <DropdownMenuSeparator />
{/* <DropdownMenuItem className="gap-x-2" onClick={() => onSelectRestartReplica()}>
Restart replica
</DropdownMenuItem> */}
{/* <DropdownMenuItem className="gap-x-2" onClick={() => onSelectResizeReplica()}>
Resize replica
</DropdownMenuItem> */}
- <DropdownMenuSeparator />
<DropdownMenuItem className="gap-x-2" onClick={() => onSelectDropReplica()}>
Drop replica
</DropdownMenuItem>
diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/MapView.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/MapView.tsx
index 3c77d1bea67..fb606996d5d 100644
--- a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/MapView.tsx
+++ b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/MapView.tsx
@@ -22,27 +22,20 @@ import {
ScrollArea,
} from 'ui'
+import { Database, useReadReplicasQuery } from 'data/read-replicas/replicas-query'
+import { formatDatabaseID } from 'data/read-replicas/replicas.utils'
import { AWS_REGIONS_KEYS, BASE_PATH, PROJECT_STATUS } from 'lib/constants'
import { AVAILABLE_REPLICA_REGIONS } from './InstanceConfiguration.constants'
import GeographyData from './MapData.json'
-import { Database, useReadReplicasQuery } from 'data/read-replicas/replicas-query'
-import { formatDatabaseID } from 'data/read-replicas/replicas.utils'
// [Joshen] Foresee that we'll skip this view for initial launch
interface MapViewProps {
onSelectDeployNewReplica: (region: AWS_REGIONS_KEYS) => void
- onSelectRestartReplica: (database: Database) => void
- onSelectResizeReplica: (database: Database) => void
onSelectDropReplica: (database: Database) => void
}
-const MapView = ({
- onSelectDeployNewReplica,
- onSelectRestartReplica,
- onSelectResizeReplica,
- onSelectDropReplica,
-}: MapViewProps) => {
+const MapView = ({ onSelectDeployNewReplica, onSelectDropReplica }: MapViewProps) => {
const { ref } = useParams()
const [mount, setMount] = useState(false)
const [zoom, setZoom] = useState<number>(1.5)
@@ -290,18 +283,6 @@ const MapView = ({
View connection string
</Link>
</DropdownMenuItem>
- {/* <DropdownMenuItem
- className="gap-x-2"
- onClick={() => onSelectRestartReplica(database)}
- >
- Restart replica
- </DropdownMenuItem>
- <DropdownMenuItem
- className="gap-x-2"
- onClick={() => onSelectResizeReplica(database)}
- >
- Resize replica
- </DropdownMenuItem> */}
<div className="border-t" />
<DropdownMenuItem
className="gap-x-2"
diff --git a/apps/studio/components/interfaces/Support/SupportForm.tsx b/apps/studio/components/interfaces/Support/SupportForm.tsx
index 81258d829c8..7545bda0b21 100644
--- a/apps/studio/components/interfaces/Support/SupportForm.tsx
+++ b/apps/studio/components/interfaces/Support/SupportForm.tsx
@@ -1,6 +1,5 @@
import { useParams } from 'common'
import { CLIENT_LIBRARIES } from 'common/constants'
-import { observer } from 'mobx-react-lite'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { ChangeEvent, useEffect, useRef, useState } from 'react'
@@ -28,17 +27,17 @@ import ShimmeringLoader from 'components/ui/ShimmeringLoader'
import { getProjectAuthConfig } from 'data/auth/auth-config-query'
import { useSendSupportTicketMutation } from 'data/feedback/support-ticket-send'
import { useOrganizationsQuery } from 'data/organizations/organizations-query'
+import { Project } from 'data/projects/project-detail-query'
import { useProjectsQuery } from 'data/projects/projects-query'
+import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
import { useFlag, useStore } from 'hooks'
import useLatest from 'hooks/misc/useLatest'
import { detectBrowser } from 'lib/helpers'
import { useProfile } from 'lib/profile'
+import { HelpCircle } from 'lucide-react'
import DisabledStateForFreeTier from './DisabledStateForFreeTier'
import { CATEGORY_OPTIONS, SERVICE_OPTIONS, SEVERITY_OPTIONS } from './Support.constants'
import { formatMessage, uploadAttachments } from './SupportForm.utils'
-import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
-import { Project } from 'data/projects/project-detail-query'
-import { HelpCircle } from 'lucide-react'
const MAX_ATTACHMENTS = 5
const INCLUDE_DISCUSSIONS = ['Problem', 'Database_unresponsive']
@@ -122,16 +121,6 @@ const SupportForm = ({ setSentCategory }: SupportFormProps) => {
orgSlug: selectedOrganizationSlug,
})
- useEffect(() => {
- if (!uploadedFiles) return
- const objectUrls = uploadedFiles.map((file) => URL.createObjectURL(file))
- setUploadedDataUrls(objectUrls)
-
- return () => {
- objectUrls.forEach((url: any) => URL.revokeObjectURL(url))
- }
- }, [uploadedFiles])
-
const { profile } = useProfile()
const respondToEmail = profile?.primary_email ?? 'your email'
@@ -239,6 +228,23 @@ const SupportForm = ({ setSentCategory }: SupportFormProps) => {
const ipv4MigrationStringMatched = ipv4MigrationStrings.some((str) => textAreaValue.includes(str))
+ useEffect(() => {
+ if (!uploadedFiles) return
+ const objectUrls = uploadedFiles.map((file) => URL.createObjectURL(file))
+ setUploadedDataUrls(objectUrls)
+
+ return () => {
+ objectUrls.forEach((url: any) => URL.revokeObjectURL(url))
+ }
+ }, [uploadedFiles])
+
+ useEffect(() => {
+ if (isSuccessProjects && ref !== undefined) {
+ const selectedProjectFromUrl = projects.find((project) => project.ref === ref)
+ if (selectedProjectFromUrl !== undefined) setSelectedProjectRef(selectedProjectFromUrl.ref)
+ }
+ }, [isSuccessProjects])
+
return (
<Form id="support-form" initialValues={initialValues} validate={onValidate} onSubmit={onSubmit}>
{({ resetForm, values }: any) => {
@@ -295,7 +301,12 @@ const SupportForm = ({ setSentCategory }: SupportFormProps) => {
}
resetForm({ values: updatedValues, initialValues: updatedValues })
}
- }, [isSuccessProjects, isSuccessOrganizations])
+ }, [
+ isSuccessProjects,
+ isSuccessOrganizations,
+ selectedProjectRef,
+ selectedOrganizationSlug,
+ ])
// Populate fields when router is ready, required when navigating to
// support form on a refresh browser session
@@ -821,4 +832,4 @@ const SupportForm = ({ setSentCategory }: SupportFormProps) => {
)
}
-export default observer(SupportForm)
+export default SupportForm
diff --git a/apps/studio/data/read-replicas/replica-remove-mutation.ts b/apps/studio/data/read-replicas/replica-remove-mutation.ts
index be4f655bfa7..416830d6a6b 100644
--- a/apps/studio/data/read-replicas/replica-remove-mutation.ts
+++ b/apps/studio/data/read-replicas/replica-remove-mutation.ts
@@ -9,6 +9,7 @@ import { Database } from './replicas-query'
export type ReadReplicaRemoveVariables = {
projectRef: string
identifier: string
+ skipInvalidateOnSuccess?: boolean
}
export async function removeReadReplica({ projectRef, identifier }: ReadReplicaRemoveVariables) {
@@ -39,17 +40,19 @@ export const useReadReplicaRemoveMutation = ({
(vars) => removeReadReplica(vars),
{
async onSuccess(data, variables, context) {
- const { projectRef, identifier } = variables
+ const { projectRef, identifier, skipInvalidateOnSuccess } = variables
- // [Joshen] Just FYI, will remove this once API changes to remove the need for optimistic rendering
- queryClient.setQueriesData<any>(replicaKeys.list(projectRef), (old: any) => {
- return old.filter((db: Database) => db.identifier !== identifier)
- })
+ if (!!skipInvalidateOnSuccess) {
+ // [Joshen] Just FYI, will remove this once API changes to remove the need for optimistic rendering
+ queryClient.setQueriesData<any>(replicaKeys.list(projectRef), (old: any) => {
+ return old.filter((db: Database) => db.identifier !== identifier)
+ })
- setTimeout(async () => {
- await queryClient.invalidateQueries(replicaKeys.list(projectRef))
- await queryClient.invalidateQueries(replicaKeys.loadBalancers(projectRef))
- }, 5000)
+ setTimeout(async () => {
+ await queryClient.invalidateQueries(replicaKeys.list(projectRef))
+ await queryClient.invalidateQueries(replicaKeys.loadBalancers(projectRef))
+ }, 5000)
+ }
await onSuccess?.(data, variables, context)
},