Skip to content

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

Disable restores if project paused for longer than 90 days (#27053)

Joshen Lima6b2b93f92ea
diff --git a/apps/studio/components/layouts/ProjectLayout/ProjectPausedState.tsx b/apps/studio/components/layouts/ProjectLayout/ProjectPausedState.tsx
index 17b09b04543..9a9dd016528 100644
--- a/apps/studio/components/layouts/ProjectLayout/ProjectPausedState.tsx
+++ b/apps/studio/components/layouts/ProjectLayout/ProjectPausedState.tsx
@@ -1,19 +1,33 @@
import * as Tooltip from '@radix-ui/react-tooltip'
import { PermissionAction } from '@supabase/shared-types/out/constants'
import { useQueryClient } from '@tanstack/react-query'
+import { ExternalLink, PauseCircle } from 'lucide-react'
import Link from 'next/link'
import { useState } from 'react'
import toast from 'react-hot-toast'
import { useParams } from 'common'
+import { useBackupsQuery } from 'data/database/backups-query'
import { useFreeProjectLimitCheckQuery } from 'data/organizations/free-project-limit-check-query'
+import { useProjectPauseStatusQuery } from 'data/projects/project-pause-status-query'
import { useProjectRestoreMutation } from 'data/projects/project-restore-mutation'
import { setProjectStatus } from 'data/projects/projects-query'
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
import { useCheckPermissions, useSelectedOrganization } from 'hooks'
import { PROJECT_STATUS } from 'lib/constants'
-import { Button, IconPauseCircle, Modal } from 'ui'
+import {
+ AlertDescription_Shadcn_,
+ AlertTitle_Shadcn_,
+ Alert_Shadcn_,
+ Button,
+ Modal,
+ TooltipContent_Shadcn_,
+ TooltipTrigger_Shadcn_,
+ Tooltip_Shadcn_,
+ cn,
+} from 'ui'
import ConfirmModal from 'ui-patterns/Dialogs/ConfirmDialog'
+import { WarningIcon } from 'ui-patterns/Icons/StatusIcons'
import { useProjectContext } from './ProjectContext'
export interface ProjectPausedStateProps {
@@ -23,24 +37,35 @@ export interface ProjectPausedStateProps {
const ProjectPausedState = ({ product }: ProjectPausedStateProps) => {
const { ref } = useParams()
const queryClient = useQueryClient()
- const selectedOrganization = useSelectedOrganization()
const { project } = useProjectContext()
+ const selectedOrganization = useSelectedOrganization()
+
const orgSlug = selectedOrganization?.slug
const { data: subscription } = useOrgSubscriptionQuery({ orgSlug })
+ const { data: pauseStatus } = useProjectPauseStatusQuery(
+ { ref },
+ { enabled: project?.status === PROJECT_STATUS.INACTIVE }
+ )
const isFreePlan = subscription?.plan?.id === 'free'
+ const isRestoreDisabled = !pauseStatus?.can_restore
const { data: membersExceededLimit } = useFreeProjectLimitCheckQuery(
{ slug: orgSlug },
{ enabled: isFreePlan }
)
- const hasMembersExceedingFreeTierLimit = (membersExceededLimit || []).length > 0
+ const { data: backups } = useBackupsQuery({ projectRef: ref })
+ const sortedBackups = (backups?.backups ?? []).sort(
+ (a, b) => new Date(b.inserted_at).valueOf() - new Date(a.inserted_at).valueOf()
+ )
+ const latestBackup = sortedBackups[0]
+ const hasMembersExceedingFreeTierLimit = (membersExceededLimit || []).length > 0
const [showConfirmRestore, setShowConfirmRestore] = useState(false)
const [showFreeProjectLimitWarning, setShowFreeProjectLimitWarning] = useState(false)
const { mutate: restoreProject } = useProjectRestoreMutation({
- onSuccess: (res, variables) => {
+ onSuccess: (_, variables) => {
setProjectStatus(queryClient, variables.ref, PROJECT_STATUS.RESTORING)
toast.success('Restoring project')
},
@@ -70,91 +95,157 @@ const ProjectPausedState = ({ product }: ProjectPausedStateProps) => {
<div className="space-y-4">
<div className="w-full mx-auto mb-16 max-w-7xl">
<div className="mx-6 flex h-[500px] items-center justify-center rounded border border-overlay bg-surface-100 p-8">
- <div className="grid w-[480px] gap-4">
+ <div className="grid w-[550px] gap-4">
<div className="mx-auto flex max-w-[300px] items-center justify-center space-x-4 lg:space-x-8">
- <IconPauseCircle className="text-foreground-light" size={50} strokeWidth={1.5} />
+ <PauseCircle className="text-foreground-light" size={50} strokeWidth={1.5} />
</div>
- <div className="space-y-2">
- <p className="text-center">
- The project "{project?.name ?? ''}" is currently paused.
- </p>
- <p className="text-sm text-foreground-light text-center">
- All of your project's data is still intact, but your project is inaccessible while
- paused.{' '}
- {product !== undefined ? (
- <>
- Restore this project to access the{' '}
- <span className="text-brand">{product}</span> page
- </>
- ) : (
- 'Restore this project and get back to building the next big thing!'
- )}
- </p>
- {isFreePlan && (
- <p className="text-sm text-foreground-light text-center">
- You can also prevent project pausing in the future by upgrading to Pro.
+ <div className="flex flex-col gap-y-2">
+ <div className="flex flex-col gap-y-1">
+ <p className="text-center">
+ The project "{project?.name ?? ''}" is currently paused.
</p>
- )}
- {!isFreePlan && (
<p className="text-sm text-foreground-light text-center">
- Unpaused projects count towards compute usage. For every hour your instance is
- active, we'll bill you based on the instance size of your project. See{' '}
- <Link
- href="https://supabase.com/docs/guides/platform/org-based-billing#usage-based-billing-for-compute"
- target="_blank"
- rel="noreferrer"
- className="underline"
- >
- Compute Instance Usage Billing
- </Link>{' '}
- for more details.
+ All of your project's data is still intact, but your project is inaccessible
+ while paused.{' '}
+ {product !== undefined ? (
+ <>
+ Restore this project to access the{' '}
+ <span className="text-brand">{product}</span> page
+ </>
+ ) : (
+ 'Restore this project and get back to building!'
+ )}
</p>
+ </div>
+
+ {isRestoreDisabled ? (
+ <Alert_Shadcn_ variant="warning">
+ <WarningIcon />
+ <AlertTitle_Shadcn_>
+ Project cannot be restored through the dashboard
+ </AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>
+ This project has been paused for over{' '}
+ <span className="text-foreground">
+ {pauseStatus?.max_days_till_restore_disabled ?? 90} days
+ </span>{' '}
+ and cannot be restored through the dashboard. However, your data remains
+ intact and can be downloaded as a backup.
+ </AlertDescription_Shadcn_>
+ <AlertDescription_Shadcn_ className="flex items-center gap-x-2 mt-3">
+ <Tooltip_Shadcn_>
+ <TooltipTrigger_Shadcn_ asChild>
+ <Button type="default" disabled={latestBackup === undefined}>
+ Download backup
+ </Button>
+ </TooltipTrigger_Shadcn_>
+ {latestBackup === undefined && (
+ <TooltipContent_Shadcn_ side="bottom">
+ No backups available
+ </TooltipContent_Shadcn_>
+ )}
+ </Tooltip_Shadcn_>
+ {/* [Joshen] To update this once we have docs ready */}
+ {/* <Button asChild type="default" icon={<ExternalLink />}>
+ <a href="/" target="_blank" rel="noreferrer">
+ Documentation
+ </a>
+ </Button> */}
+ </AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
+ ) : isFreePlan ? (
+ <>
+ <p className="text-sm text-foreground-light text-center">
+ To prevent future pauses, consider upgrading to Pro.
+ </p>
+ <Alert_Shadcn_>
+ <AlertTitle_Shadcn_>
+ Project can be restored through the dashboard within the next{' '}
+ {pauseStatus.remaining_days_till_restore_disabled} day
+ {(pauseStatus?.remaining_days_till_restore_disabled ?? 0) > 1 ? 's' : ''}
+ </AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>
+ Free projects cannot be restored through the dashboard if they are paused
+ for more than{' '}
+ <span className="text-foreground">
+ {pauseStatus.max_days_till_restore_disabled} days
+ </span>
+ . However, your database backup will still be available for download.
+ </AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
+ </>
+ ) : null}
+
+ {!isFreePlan && (
+ <Alert_Shadcn_>
+ <WarningIcon />
+ <AlertTitle_Shadcn_>
+ Project will count towards compute usage once restored
+ </AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>
+ For every hour your instance is active, we will bill you based on the instance
+ size of your project.
+ </AlertDescription_Shadcn_>
+ <AlertDescription_Shadcn_ className="mt-3">
+ <Button asChild type="default" icon={<ExternalLink />}>
+ <a
+ href="https://supabase.com/docs/guides/platform/org-based-billing#usage-based-billing-for-compute"
+ target="_blank"
+ rel="noreferrer"
+ >
+ More information
+ </a>
+ </Button>
+ </AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
)}
</div>
- <div className="flex items-center justify-center gap-4">
- <Tooltip.Root delayDuration={0}>
- <Tooltip.Trigger asChild>
- <Button
- size="tiny"
- type="primary"
- disabled={!canResumeProject}
- onClick={onSelectRestore}
- >
- Restore project
+ {!isRestoreDisabled && (
+ <div className="flex items-center justify-center gap-4">
+ <Tooltip.Root delayDuration={0}>
+ <Tooltip.Trigger asChild>
+ <Button
+ size="tiny"
+ type="primary"
+ disabled={!canResumeProject}
+ onClick={onSelectRestore}
+ >
+ Restore project
+ </Button>
+ </Tooltip.Trigger>
+ {!canResumeProject && (
+ <Tooltip.Portal>
+ <Tooltip.Content side="bottom">
+ <Tooltip.Arrow className="radix-tooltip-arrow" />
+ <div
+ className={cn(
+ 'border border-background',
+ 'rounded bg-alternative py-1 px-2 leading-none shadow'
+ )}
+ >
+ <span className="text-xs text-foreground">
+ You need additional permissions to resume this project
+ </span>
+ </div>
+ </Tooltip.Content>
+ </Tooltip.Portal>
+ )}
+ </Tooltip.Root>
+ {isFreePlan ? (
+ <Button asChild type="default">
+ <Link href={`/org/${orgSlug}/billing?panel=subscriptionPlan`}>
+ Upgrade to Pro
+ </Link>
+ </Button>
+ ) : (
+ <Button asChild type="default">
+ <Link href={`/project/${ref}/settings/general`}>View project settings</Link>
</Button>
- </Tooltip.Trigger>
- {!canResumeProject && (
- <Tooltip.Portal>
- <Tooltip.Content side="bottom">
- <Tooltip.Arrow className="radix-tooltip-arrow" />
- <div
- className={[
- 'rounded bg-alternative py-1 px-2 leading-none shadow', // background
- 'border border-background', //border
- ].join(' ')}
- >
- <span className="text-xs text-foreground">
- You need additional permissions to resume this project
- </span>
- </div>
- </Tooltip.Content>
- </Tooltip.Portal>
)}
- </Tooltip.Root>
- {isFreePlan ? (
- <Button asChild type="default">
- <Link href={`/org/${orgSlug}/billing?panel=subscriptionPlan`}>
- Upgrade to Pro
- </Link>
- </Button>
- ) : (
- <Button asChild type="default">
- <Link href={`/project/${ref}/settings/general`}>View project settings</Link>
- </Button>
- )}
- </div>
+ </div>
+ )}
</div>
</div>
</div>
diff --git a/apps/studio/data/projects/keys.ts b/apps/studio/data/projects/keys.ts
index 0a352b78df2..e4be8b5a3d5 100644
--- a/apps/studio/data/projects/keys.ts
+++ b/apps/studio/data/projects/keys.ts
@@ -12,4 +12,6 @@ export const projectKeys = {
projectRef: string | undefined,
targetOrganizationSlug: string | undefined
) => ['projects', 'transfer', projectRef, targetOrganizationSlug, 'preview'] as const,
+ pauseStatus: (projectRef: string | undefined) =>
+ ['projects', projectRef, 'pause-status'] as const,
}
diff --git a/apps/studio/data/projects/project-pause-status-query.ts b/apps/studio/data/projects/project-pause-status-query.ts
new file mode 100644
index 00000000000..c84c0b790ec
--- /dev/null
+++ b/apps/studio/data/projects/project-pause-status-query.ts
@@ -0,0 +1,41 @@
+import { useQuery, UseQueryOptions } from '@tanstack/react-query'
+
+import { get, handleError } from 'data/fetchers'
+import type { ResponseError } from 'types'
+import { projectKeys } from './keys'
+
+export type ProjectPauseStatusVariables = { ref?: string }
+
+export async function getProjectPausedStatus(
+ { ref }: ProjectPauseStatusVariables,
+ signal?: AbortSignal
+) {
+ if (!ref) throw new Error('Project ref is required')
+
+ const { data, error } = await get('/platform/projects/{ref}/pause/status', {
+ params: { path: { ref } },
+ signal,
+ })
+
+ if (error) handleError(error)
+ return data
+}
+
+export type ProjectPauseStatusData = Awaited<ReturnType<typeof getProjectPausedStatus>>
+export type ProjectPauseStatusError = ResponseError
+
+export const useProjectPauseStatusQuery = <TData = ProjectPauseStatusData>(
+ { ref }: ProjectPauseStatusVariables,
+ {
+ enabled = true,
+ ...options
+ }: UseQueryOptions<ProjectPauseStatusData, ProjectPauseStatusError, TData> = {}
+) =>
+ useQuery<ProjectPauseStatusData, ProjectPauseStatusError, TData>(
+ projectKeys.pauseStatus(ref),
+ ({ signal }) => getProjectPausedStatus({ ref }, signal),
+ {
+ enabled: enabled && typeof ref !== 'undefined',
+ ...options,
+ }
+ )
diff --git a/packages/api-types/types/api.d.ts b/packages/api-types/types/api.d.ts
index d2c6d209729..510022ac7c3 100644
--- a/packages/api-types/types/api.d.ts
+++ b/packages/api-types/types/api.d.ts
@@ -580,6 +580,10 @@ export interface paths {
/** Pauses the project */
post: operations['PauseController_pauseProject']
}
+ '/platform/projects/{ref}/pause/status': {
+ /** Gets the latest pause event for a project if a project is paused */
+ get: operations['PauseController_getProject']
+ }
'/platform/projects/{ref}/resize': {
/** Resize database disk */
post: operations['ResizeController_resizeDatabase']
@@ -1450,6 +1454,10 @@ export interface paths {
/** Pauses the project */
post: operations['PauseController_pauseProject']
}
+ '/v0/projects/{ref}/pause/status': {
+ /** Gets the latest pause event for a project if a project is paused */
+ get: operations['PauseController_getProject']
+ }
'/v0/projects/{ref}/resize': {
/** Resize database disk */
post: operations['ResizeController_resizeDatabase']
@@ -3919,6 +3927,11 @@ export interface components {
databases: components['schemas']['LoadBalancerDatabase'][]
}
Buffer: Record<string, never>
+ PauseStatusResponse: {
+ max_days_till_restore_disabled: number | null
+ remaining_days_till_restore_disabled: number | null
+ can_restore: boolean | null
+ }
ResizeBody: {
volume_size_gb: number
}
@@ -10124,6 +10137,22 @@ export interface operations {
}
}
}
+ /** Gets the latest pause event for a project if a project is paused */
+ PauseController_getProject: {
+ parameters: {
+ path: {
+ /** @description Project ref */
+ ref: string
+ }
+ }
+ responses: {
+ 200: {
+ content: {
+ 'application/json': components['schemas']['PauseStatusResponse']
+ }
+ }
+ }
+ }
/** Resize database disk */
ResizeController_resizeDatabase: {
parameters: {