The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Update restore validity logic for paused projects behind feature flag (#27404)
Joshen Lim0bf85c32d6f0
diff --git a/apps/studio/components/layouts/ProjectLayout/ProjectPausedState.tsx b/apps/studio/components/layouts/ProjectLayout/ProjectPausedState.tsxindex a2e9a794d40..4f17a56ecba 100644--- a/apps/studio/components/layouts/ProjectLayout/ProjectPausedState.tsx+++ b/apps/studio/components/layouts/ProjectLayout/ProjectPausedState.tsx@@ -1,18 +1,18 @@import { PermissionAction } from '@supabase/shared-types/out/constants'import { useQueryClient } from '@tanstack/react-query'-import { ExternalLink, PauseCircle } from 'lucide-react'+import { Download, 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 { useBackupDownloadMutation } from 'data/database/backup-download-mutation'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 { useCheckPermissions, useFlag, useSelectedOrganization } from 'hooks'import { PROJECT_STATUS } from 'lib/constants'import {AlertDescription_Shadcn_,@@ -27,6 +27,9 @@ import {import ConfirmModal from 'ui-patterns/Dialogs/ConfirmDialog'import { WarningIcon } from 'ui-patterns/Icons/StatusIcons'import { useProjectContext } from './ProjectContext'+import { GenericSkeletonLoader } from 'ui-patterns'+import dayjs from 'dayjs'+import AlertError from 'components/ui/AlertError'export interface ProjectPausedStateProps {product?: string@@ -37,26 +40,33 @@ const ProjectPausedState = ({ product }: ProjectPausedStateProps) => {const queryClient = useQueryClient()const { project } = useProjectContext()const selectedOrganization = useSelectedOrganization()+ const enableDisablingOfProjectRestores90DayLimit = useFlag('enforceNinetyDayUnpauseExpiry')const orgSlug = selectedOrganization?.slugconst { data: subscription } = useOrgSubscriptionQuery({ orgSlug })- // const { data: pauseStatus } = useProjectPauseStatusQuery(- // { ref },- // { enabled: project?.status === PROJECT_STATUS.INACTIVE }- // )+ const {+ data: pauseStatus,+ error: pauseStatusError,+ isError,+ isSuccess,+ isLoading,+ } = useProjectPauseStatusQuery(+ { ref },+ {+ enabled:+ project?.status === PROJECT_STATUS.INACTIVE && enableDisablingOfProjectRestores90DayLimit,+ }+ )const isFreePlan = subscription?.plan?.id === 'free'- const isRestoreDisabled = false // !pauseStatus?.can_restore+ const isRestoreDisabled =+ enableDisablingOfProjectRestores90DayLimit && isSuccess && !pauseStatus.can_restore+ const latestBackup = pauseStatus?.latest_downloadable_backup_idconst { data: membersExceededLimit } = useFreeProjectLimitCheckQuery({ slug: orgSlug },{ enabled: isFreePlan })- 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 > 0const [showConfirmRestore, setShowConfirmRestore] = useState(false)@@ -69,6 +79,19 @@ const ProjectPausedState = ({ product }: ProjectPausedStateProps) => {},})+ const { mutate: downloadBackup, isLoading: isDownloading } = useBackupDownloadMutation({+ onSuccess: (res) => {+ const { fileUrl } = res++ // Trigger browser download by create,trigger and remove tempLink+ const tempLink = document.createElement('a')+ tempLink.href = fileUrl+ document.body.appendChild(tempLink)+ tempLink.click()+ document.body.removeChild(tempLink)+ },+ })+const canResumeProject = useCheckPermissions(PermissionAction.INFRA_EXECUTE,'queue_jobs.projects.initialize_or_resume'@@ -88,6 +111,24 @@ const ProjectPausedState = ({ product }: ProjectPausedStateProps) => {restoreProject({ ref: project.ref })}+ const onSelectDownloadBackup = () => {+ if (ref === undefined) return console.error('Project ref is required')+ if (!latestBackup) return toast.error('No backups available for download')++ downloadBackup({+ ref,+ backup: {+ id: latestBackup,+ // [Joshen] Just FYI these params aren't required for the download backup request+ // API types need to be updated+ project_id: -1,+ inserted_at: '',+ isPhysicalBackup: false,+ status: {},+ },+ })+ }+return (<><div className="space-y-4">@@ -117,88 +158,107 @@ const ProjectPausedState = ({ product }: ProjectPausedStateProps) => {</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}- className="pointer-events-auto"- >- Download backup- </Button>- </TooltipTrigger_Shadcn_>- {latestBackup === undefined && (- <TooltipContent_Shadcn_ side="bottom">- No backups available- </TooltipContent_Shadcn_>- )}- </Tooltip_Shadcn_>- </AlertDescription_Shadcn_>- </Alert_Shadcn_>- ) : isFreePlan ? (+ {isLoading && <GenericSkeletonLoader />}+ {isError && (+ <AlertError error={pauseStatusError} subject="Failed to retrieve pause status" />+ )}+ {isSuccess && (<>- <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_>+ {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"+ icon={<Download />}+ loading={isDownloading}+ disabled={!latestBackup}+ className="pointer-events-auto"+ onClick={() => onSelectDownloadBackup()}+ >+ Download backup+ </Button>+ </TooltipTrigger_Shadcn_>+ {!latestBackup && (+ <TooltipContent_Shadcn_ side="bottom">+ No backups available, please reach out via support for assistance+ </TooltipContent_Shadcn_>+ )}+ </Tooltip_Shadcn_>+ </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>+ . The latest that your project can be restored is by{' '}+ <span className="text-foreground">+ {dayjs()+ .utc()+ .add(pauseStatus.max_days_till_restore_disabled ?? 0, 'day')+ .format('DD MMM YYYY')}+ </span>+ . However, your database backup will still be available for download+ thereafter.+ </AlertDescription_Shadcn_>+ </Alert_Shadcn_>+ </>+ ) : (+ <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_>+ )}</>- ) : 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>- {!isRestoreDisabled && (+ {isSuccess && !isRestoreDisabled && (<div className="flex items-center justify-center gap-4"><Tooltip_Shadcn_><TooltipTrigger_Shadcn_ asChild>diff --git a/apps/studio/data/organizations/organization-payment-methods-query.ts b/apps/studio/data/organizations/organization-payment-methods-query.tsindex 39b278254e1..610142e4668 100644--- a/apps/studio/data/organizations/organization-payment-methods-query.ts+++ b/apps/studio/data/organizations/organization-payment-methods-query.ts@@ -5,8 +5,7 @@ import { get, handleError } from 'data/fetchers'import { components } from 'api-types'export type OrganizationPaymentMethodsVariables = { slug?: string }-export type OrganizationPaymentMethodsResponse = components['schemas']['PaymentsResponseV2']-export type OrganizationPaymentMethod = components['schemas']['PaymentV2']+export type OrganizationPaymentMethod = components['schemas']['Payment']export async function getOrganizationPaymentMethods({ slug }: OrganizationPaymentMethodsVariables,@@ -25,11 +24,9 @@ export async function getOrganizationPaymentMethods(},signal,})- if (error) handleError(error)- // Due to API versioning, this is not correctly recognized until the old endpoint is removed- // @ts-ignore- return data as OrganizationPaymentMethodsResponse+ if (error) handleError(error)+ return data}export type OrganizationPaymentMethodsData = Awaited<diff --git a/packages/api-types/types/api.d.ts b/packages/api-types/types/api.d.tsindex 1f00abc4776..9bbf3572900 100644--- a/packages/api-types/types/api.d.ts+++ b/packages/api-types/types/api.d.ts@@ -157,8 +157,6 @@ export interface paths {get: operations['CustomerController_getCustomer']/** Updates the billing customer */put: operations['updateCustomerV2']- /** Updates the Stripe customer */- patch: operations['CustomerController_updateCustomer']}'/platform/organizations/{slug}/roles': {/** Gets the given organization's roles */@@ -267,7 +265,7 @@ export interface paths {}'/platform/organizations/{slug}/payments': {/** Gets Stripe payment methods for the given organization */- get: operations['PaymentsController_getPaymentMethods']+ get: operations['getPaymentMethodsV2']/** Detach payment method with the given card ID */delete: operations['PaymentsController_detachPaymentMethod']}@@ -2582,51 +2580,11 @@ export interface components {email: stringaddress: components['schemas']['CustomerBillingAddress'] | nullbalance: number- invoice_settings: Record<string, never>billing_via_partner: boolean}BillingCustomerUpdateBody: {address?: components['schemas']['CustomerBillingAddress']}- CustomerUpdateResponse: {- id: string- object: string- address: Record<string, never>- balance: number- cash_balance?: Record<string, never>- created: number- currency: string- default_currency?: string- default_source: string- delinquent: boolean- description: string- discount: Record<string, never>- email: string- invoice_credit_balance?: Record<string, never>- invoice_prefix: string- invoice_settings: Record<string, never>- livemode: boolean- metadata: Record<string, never>- name: string- next_invoice_sequence?: number- phone: string- preferred_locales: string[]- shipping: Record<string, never>- sources?: Record<string, never>- subscriptions?: Record<string, never>- tax?: Record<string, never>- tax_exempt?: string- tax_ids?: Record<string, never>- test_clock?: Record<string, never>- lastResponse: {- headers?: Record<string, never>- requestId?: string- statusCode?: number- apiVersion?: string- idempotencyKey?: string- stripeAccount?: string- }- }OrganizationRole: {id: numbername: string@@ -2819,70 +2777,16 @@ export interface components {exp_year: numberlast4: string}- PaymentV2: {+ Payment: {id: stringcard?: components['schemas']['PaymentMethodCard']created: numbertype: stringis_default: boolean}- PaymentsResponseV2: {- defaultPaymentMethodId: string | null- data: components['schemas']['PaymentV2'][]- }- Payment: {- id: string- object: string- acss_debit?: Record<string, never>- affirm?: Record<string, never>- afterpay_clearpay?: Record<string, never>- alipay?: Record<string, never>- au_becs_debit?: Record<string, never>- bacs_debit?: Record<string, never>- bancontact?: Record<string, never>- billing_details: Record<string, never>- blik?: Record<string, never>- boleto?: Record<string, never>- card?: Record<string, never>- card_present?: Record<string, never>- created: number- customer: Record<string, never>- customer_balance?: Record<string, never>- eps?: Record<string, never>- fpx?: Record<string, never>- giropay?: Record<string, never>- grabpay?: Record<string, never>- ideal?: Record<string, never>- interac_present?: Record<string, never>- klarna?: Record<string, never>- konbini?: Record<string, never>- link?: Record<string, never>- livemode: boolean- metadata: Record<string, never>- oxxo?: Record<string, never>- p24?: Record<string, never>- paynow?: Record<string, never>- promptpay?: Record<string, never>- radar_options?: Record<string, never>- sepa_debit?: Record<string, never>- sofort?: Record<string, never>- type: string- us_bank_account?: Record<string, never>- wechat_pay?: Record<string, never>- }PaymentsResponse: {- object: string+ defaultPaymentMethodId: string | nulldata: components['schemas']['Payment'][]- has_more: boolean- url: string- lastResponse: {- headers?: Record<string, never>- requestId?: string- statusCode?: number- apiVersion?: string- idempotencyKey?: string- stripeAccount?: string- }}DetachPaymentMethodBody: {card_id: string@@ -2894,37 +2798,8 @@ export interface components {hcaptchaToken: string}SetupIntentResponse: {- id: string- object: string- application: Record<string, never>- attach_to_self?: boolean- cancellation_reason: stringclient_secret: string- created: number- customer: Record<string, never>- description: string- flow_directions: Record<string, never>- last_setup_error: Record<string, never>- latest_attempt: Record<string, never>- livemode: boolean- mandate: Record<string, never>- metadata: Record<string, never>- next_action: Record<string, never>- on_behalf_of: Record<string, never>payment_method: Record<string, never>- payment_method_options: Record<string, never>- payment_method_types: string[]- single_use_mandate: Record<string, never>- status: string- usage: string- lastResponse: {- headers?: Record<string, never>- requestId?: string- statusCode?: number- apiVersion?: string- idempotencyKey?: string- stripeAccount?: string- }}/** @enum {string} */BillingPlanId: 'free' | 'pro' | 'team' | 'enterprise'@@ -2978,12 +2853,6 @@ export interface components {name: stringref: string}- PaymentMethodCardDetails: {- last_4_digits: string- brand: string- expiry_month: number- expiry_year: number- }ScheduledPlanChange: {target_plan: components['schemas']['BillingPlanId']/** Format: date-time */@@ -3000,8 +2869,6 @@ export interface components {addons: components['schemas']['BillingSubscriptionAddon'][]project_addons: components['schemas']['BillingProjectAddonResponse'][]payment_method_type: string- payment_method_id?: string- payment_method_card_details?: components['schemas']['PaymentMethodCardDetails']billing_via_partner: boolean/** @enum {string} */billing_partner: 'fly' | 'aws'@@ -3947,9 +3814,10 @@ export interface components {}Buffer: Record<string, never>PauseStatusResponse: {- max_days_till_restore_disabled: number | null+ max_days_till_restore_disabled: numberremaining_days_till_restore_disabled: number | null- can_restore: boolean | null+ can_restore: boolean+ latest_downloadable_backup_id: number | null}ResizeBody: {volume_size_gb: number@@ -4015,16 +3883,20 @@ export interface components {region: string/** @enum {string} */status:- | 'INACTIVE'| 'ACTIVE_HEALTHY'| 'ACTIVE_UNHEALTHY'| 'COMING_UP'- | 'UNKNOWN'| 'GOING_DOWN'+ | 'INACTIVE'| 'INIT_FAILED'| 'REMOVED'- | 'RESTORING'+ | 'RESTARTING'+ | 'UNKNOWN'| 'UPGRADING'+ | 'PAUSING'+ | 'RESTORING'+ | 'RESTORE_FAILED'+ | 'PAUSE_FAILED'subscription_id: stringconnectionString: stringkpsVersion?: string@@ -5676,6 +5548,7 @@ export interface components {default?: Record<string, never> | number | string | booleanname?: stringnames?: string[]+ array?: boolean}AttributeMapping: {keys: {@@ -6904,7 +6777,7 @@ export interface operations {}}responses: {- 200: {+ 204: {content: never}403: {@@ -6916,29 +6789,6 @@ export interface operations {}}}- /** Updates the Stripe customer */- CustomerController_updateCustomer: {- parameters: {- path: {- /** @description Organization slug */- slug: string- }- }- responses: {- 200: {- content: {- 'application/json': components['schemas']['CustomerUpdateResponse']- }- }- 403: {- content: never- }- /** @description Failed to update the Stripe customer */- 500: {- content: never- }- }- }/** Gets the given organization's roles */OrganizationRolesController_getAllRolesV2: {parameters: {@@ -7573,7 +7423,7 @@ export interface operations {}}/** Gets Stripe payment methods for the given organization */- PaymentsController_getPaymentMethods: {+ getPaymentMethodsV2: {parameters: {path: {/** @description Organization slug */