The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Fix upgrade query ui (#21865)
Joshen Lim1c5fd8b07c65
diff --git a/apps/studio/components/interfaces/Settings/General/Infrastructure/Infrastructure.tsx b/apps/studio/components/interfaces/Settings/General/Infrastructure/Infrastructure.tsxdeleted file mode 100644index 9465ba008b7..00000000000--- a/apps/studio/components/interfaces/Settings/General/Infrastructure/Infrastructure.tsx+++ /dev/null@@ -1,156 +0,0 @@-import * as Tooltip from '@radix-ui/react-tooltip'-import { useParams } from 'common'-import { observer } from 'mobx-react-lite'-import Link from 'next/link'-import { Alert, Badge, Button, IconPackage, Input } from 'ui'--import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'-import {- FormHeader,- FormPanel,- FormSection,- FormSectionContent,- FormSectionLabel,-} from 'components/ui/Forms'-import { useProjectUpgradeEligibilityQuery } from 'data/config/project-upgrade-eligibility-query'-import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'-import { useSelectedOrganization } from 'hooks'-import PauseProjectButton from './PauseProjectButton'-import { ProjectUpgradeAlert } from './ProjectUpgradeAlert'-import RestartServerButton from './RestartServerButton'--interface InfrastructureProps {}--const Infrastructure = ({}: InfrastructureProps) => {- const { ref } = useParams()- const { project } = useProjectContext()- const organization = useSelectedOrganization()- const { data: subscription } = useOrgSubscriptionQuery({ orgSlug: organization?.slug })-- const isFreeProject = subscription?.plan?.id === 'free'-- const {- data,- isLoading: isLoadingUpgradeElibility,- isError,- } = useProjectUpgradeEligibilityQuery({- projectRef: ref,- })- const { current_app_version, latest_app_version, requires_manual_intervention } = data || {}- const isOnLatestVersion = current_app_version === latest_app_version- const currentPgVersion = (current_app_version ?? '').split('supabase-postgres-')[1]- const latestPgVersion = (latest_app_version ?? '').split('supabase-postgres-')[1]-- const subject = 'Request%20for%20Postgres%20upgrade%20for%20project'- const message = `Upgrade information:%0A• Manual intervention reason: ${requires_manual_intervention}`-- return (- <div>- <FormHeader title="Infrastructure" description="" />- <FormPanel- footer={- <>- <div className="flex w-full items-center justify-between px-8 py-4">- <div>- <p className="text-sm">Restart server</p>- <div className="max-w-[420px]">- <p className="text-sm text-foreground-light">- Your project will not be available for a few minutes.- </p>- </div>- </div>- {project && <RestartServerButton />}- </div>-- {isFreeProject && (- <>- <div className="border-t border-muted" />- <div className="flex w-full items-center justify-between px-8 py-4">- <div>- <p className="text-sm">Pause project</p>- <div className="max-w-[420px]">- <p className="text-sm text-foreground-light">- Your project will not be accessible while it is paused.- </p>- </div>- </div>- {project && <PauseProjectButton />}- </div>- </>- )}- </>- }- >- <FormSection header={<FormSectionLabel>Configuration</FormSectionLabel>}>- <FormSectionContent loading={project === undefined}>- <Input readOnly disabled value={project?.cloud_provider} label="Cloud provider" />- <Input readOnly disabled value={project?.region} label="Region" />- </FormSectionContent>- </FormSection>-- <FormSection header={<FormSectionLabel>Postgres</FormSectionLabel>}>- <FormSectionContent loading={isLoadingUpgradeElibility}>- <Input- readOnly- disabled- value={- currentPgVersion ?? (isError ? 'Unable to fetch Postgres version of project' : '')- }- label="Current version"- actions={[- isOnLatestVersion && (- <Tooltip.Root delayDuration={0}>- <Tooltip.Trigger>- <Badge color="green" className="mr-1">- Latest- </Badge>- </Tooltip.Trigger>- <Tooltip.Portal>- <Tooltip.Content side="bottom">- <Tooltip.Arrow className="radix-tooltip-arrow" />- <div- className={[- 'rounded bg-alternative py-1 px-2 leading-none shadow',- 'border border-background w-[200px]',- ].join(' ')}- >- <span className="text-xs text-foreground">- Project is on the latest version of Postgres that Supabase supports- </span>- </div>- </Tooltip.Content>- </Tooltip.Portal>- </Tooltip.Root>- ),- ]}- />- {data?.eligible && <ProjectUpgradeAlert />}- {!data?.eligible && data?.requires_manual_intervention && (- <Alert- icon={<IconPackage className="text-foreground-light" strokeWidth={1.5} />}- variant="neutral"- title="A new version of Postgres is available for your project"- >- <p className="mb-3">- Please reach out to us via our support form if you are keen to upgrade your- Postgres version to the latest available ({latestPgVersion}).- </p>- <Button asChild size="tiny" type="default">- <Link- href={`/support/new?category=Database_unresponsive&ref=${ref}&subject=${subject}&message=${message}`}- target="_blank"- rel="noreferrer"- >- Contact support- </Link>- </Button>- </Alert>- )}- </FormSectionContent>- </FormSection>- </FormPanel>- </div>- )-}--export default observer(Infrastructure)diff --git a/apps/studio/components/interfaces/Settings/General/index.ts b/apps/studio/components/interfaces/Settings/General/index.tsindex be92b7554a3..904c124b6fd 100644--- a/apps/studio/components/interfaces/Settings/General/index.ts+++ b/apps/studio/components/interfaces/Settings/General/index.ts@@ -1,5 +1,4 @@export { default as General } from './General'-export { default as Infrastructure } from './Infrastructure/Infrastructure'export { default as CustomDomainConfig } from './CustomDomainConfig/CustomDomainConfig'export { default as DeleteProjectPanel } from './DeleteProjectPanel/DeleteProjectPanel'export { default as DeleteProjectButton } from './DeleteProjectPanel/DeleteProjectButton'diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureInfo.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureInfo.tsxindex 0e3b9d478c4..4fe696a9d87 100644--- a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureInfo.tsx+++ b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureInfo.tsx@@ -54,6 +54,7 @@ const InfrastructureInfo = () => {const currentPgVersion = (current_app_version ?? '').split('supabase-postgres-')[1]const latestPgVersion = (latest_app_version ?? '').split('supabase-postgres-')[1]+ const isInactive = project?.status === 'INACTIVE'const showReadReplicasUI = project?.is_read_replicas_enabledconst hasReadReplicas = (databases ?? []).length > 1const subject = 'Request%20for%20Postgres%20upgrade%20for%20project'@@ -133,132 +134,146 @@ const InfrastructureInfo = () => {</p></ScaffoldSectionDetail><ScaffoldSectionContent>- {isLoadingUpgradeEligibility && <GenericSkeletonLoader />}- {isErrorUpgradeEligibility && (- <AlertError error={error} subject="Failed to retrieve Postgres version" />- )}- {isSuccessUpgradeEligibility && (+ {isInactive ? (+ <Alert_Shadcn_>+ <AlertTitle_Shadcn_>+ Service versions cannot be retrieved while project is paused+ </AlertTitle_Shadcn_>+ <AlertDescription_Shadcn_>+ Restoring the project will update Postgres to the newest version+ </AlertDescription_Shadcn_>+ </Alert_Shadcn_>+ ) : (<>- {authEnabled && (- <Input- readOnly- disabled- label="GoTrue version"- value={project?.serviceVersions?.gotrue ?? ''}- />+ {isLoadingUpgradeEligibility && <GenericSkeletonLoader />}+ {isErrorUpgradeEligibility && (+ <AlertError error={error} subject="Failed to retrieve Postgres version" />)}- <Input- readOnly- disabled- label="PostgREST version"- value={project?.serviceVersions?.postgrest ?? ''}- />- <Input- readOnly- disabled- value={currentPgVersion}- label="Postgres version"- actions={[- isOnLatestVersion && (- <Tooltip.Root key="tooltip-latest" delayDuration={0}>- <Tooltip.Trigger>- <Badge color="green" className="mr-1">- Latest- </Badge>- </Tooltip.Trigger>- <Tooltip.Portal>- <Tooltip.Content side="bottom">- <Tooltip.Arrow className="radix-tooltip-arrow" />- <div- className={[- 'rounded bg-alternative py-1 px-2 leading-none shadow',- 'border border-background w-[200px]',- ].join(' ')}+ {isSuccessUpgradeEligibility && (+ <>+ {authEnabled && (+ <Input+ readOnly+ disabled+ label="GoTrue version"+ value={project?.serviceVersions?.gotrue ?? ''}+ />+ )}+ <Input+ readOnly+ disabled+ label="PostgREST version"+ value={project?.serviceVersions?.postgrest ?? ''}+ />+ <Input+ readOnly+ disabled+ value={currentPgVersion}+ label="Postgres version"+ actions={[+ isOnLatestVersion && (+ <Tooltip.Root key="tooltip-latest" delayDuration={0}>+ <Tooltip.Trigger>+ <Badge color="green" className="mr-1">+ Latest+ </Badge>+ </Tooltip.Trigger>+ <Tooltip.Portal>+ <Tooltip.Content side="bottom">+ <Tooltip.Arrow className="radix-tooltip-arrow" />+ <div+ className={[+ 'rounded bg-alternative py-1 px-2 leading-none shadow',+ 'border border-background w-[200px]',+ ].join(' ')}+ >+ <span className="text-xs text-foreground">+ Project is on the latest version of Postgres that Supabase+ supports+ </span>+ </div>+ </Tooltip.Content>+ </Tooltip.Portal>+ </Tooltip.Root>+ ),+ ]}+ />+ {data?.eligible && !hasReadReplicas && <ProjectUpgradeAlert />}+ {data.eligible && hasReadReplicas && (+ <Alert_Shadcn_>+ <AlertTitle_Shadcn_>+ A new version of Postgres is available for your project+ </AlertTitle_Shadcn_>+ <AlertDescription_Shadcn_>+ You will need to remove all read replicas first prior to upgrading your+ Postgrest version to the latest available ({latestPgVersion}).+ </AlertDescription_Shadcn_>+ </Alert_Shadcn_>+ )}+ {!data?.eligible && data?.requires_manual_intervention && (+ <Alert_Shadcn_ title="A new version of Postgres is available for your project">+ <AlertTitle_Shadcn_>+ A new version of Postgres is available for your project+ </AlertTitle_Shadcn_>+ <AlertDescription_Shadcn_>+ <p className="mb-3">+ Please reach out to us via our support form if you are keen to upgrade+ your Postgres version to the latest available ({latestPgVersion}).+ </p>+ <Button size="tiny" type="default" asChild>+ <Link+ href={`/support/new?category=Database_unresponsive&ref=${ref}&subject=${subject}&message=${message}`}+ target="_blank"+ rel="noreferrer">- <span className="text-xs text-foreground">- Project is on the latest version of Postgres that Supabase supports- </span>- </div>- </Tooltip.Content>- </Tooltip.Portal>- </Tooltip.Root>- ),- ]}- />- {data?.eligible && !hasReadReplicas && <ProjectUpgradeAlert />}- {data.eligible && hasReadReplicas && (- <Alert_Shadcn_>- <AlertTitle_Shadcn_>- A new version of Postgres is available for your project- </AlertTitle_Shadcn_>- <AlertDescription_Shadcn_>- You will need to remove all read replicas first prior to upgrading your- Postgrest version to the latest available ({latestPgVersion}).- </AlertDescription_Shadcn_>- </Alert_Shadcn_>- )}- {!data?.eligible && data?.requires_manual_intervention && (- <Alert_Shadcn_ title="A new version of Postgres is available for your project">- <AlertTitle_Shadcn_>- A new version of Postgres is available for your project- </AlertTitle_Shadcn_>- <AlertDescription_Shadcn_>- <p className="mb-3">- Please reach out to us via our support form if you are keen to upgrade your- Postgres version to the latest available ({latestPgVersion}).- </p>- <Button size="tiny" type="default" asChild>- <Link- href={`/support/new?category=Database_unresponsive&ref=${ref}&subject=${subject}&message=${message}`}- target="_blank"- rel="noreferrer"- >- Contact support- </Link>- </Button>- </AlertDescription_Shadcn_>- </Alert_Shadcn_>- )}- {!data?.eligible && (data?.extension_dependent_objects || []).length > 0 && (- <Alert_Shadcn_- variant="warning"- title="A new version of Postgres is available for your project"- >- <AlertTitle_Shadcn_>New version of Postgres available</AlertTitle_Shadcn_>- <AlertDescription_Shadcn_ className="flex flex-col gap-3">- <div>- <p className="mb-1">- This project cannot be upgraded due to the following extension dependent- objects:- </p>+ Contact support+ </Link>+ </Button>+ </AlertDescription_Shadcn_>+ </Alert_Shadcn_>+ )}+ {!data?.eligible && (data?.extension_dependent_objects || []).length > 0 && (+ <Alert_Shadcn_+ variant="warning"+ title="A new version of Postgres is available for your project"+ >+ <AlertTitle_Shadcn_>New version of Postgres available</AlertTitle_Shadcn_>+ <AlertDescription_Shadcn_ className="flex flex-col gap-3">+ <div>+ <p className="mb-1">+ This project cannot be upgraded due to the following extension+ dependent objects:+ </p>- <ul className="pl-4">- {(data?.extension_dependent_objects || []).map((obj) => (- <li className="list-disc" key={obj}>- {obj}- </li>- ))}- </ul>- </div>- <p>- Once the above objects are exported and removed, you can proceed to upgrade- your project, and re-import the objects after the upgrade operation is- complete. Please refer to the docs on additional extensions that might also- need to be dropped.- </p>- <div>- <Button size="tiny" type="default" asChild>- <Link- href="https://supabase.com/docs/guides/platform/migrating-and-upgrading-projects#caveats"- target="_blank"- rel="noreferrer"- >- View docs- </Link>- </Button>- </div>- </AlertDescription_Shadcn_>- </Alert_Shadcn_>+ <ul className="pl-4">+ {(data?.extension_dependent_objects || []).map((obj) => (+ <li className="list-disc" key={obj}>+ {obj}+ </li>+ ))}+ </ul>+ </div>+ <p>+ Once the above objects are exported and removed, you can proceed to+ upgrade your project, and re-import the objects after the upgrade+ operation is complete. Please refer to the docs on additional extensions+ that might also need to be dropped.+ </p>+ <div>+ <Button size="tiny" type="default" asChild>+ <Link+ href="https://supabase.com/docs/guides/platform/migrating-and-upgrading-projects#caveats"+ target="_blank"+ rel="noreferrer"+ >+ View docs+ </Link>+ </Button>+ </div>+ </AlertDescription_Shadcn_>+ </Alert_Shadcn_>+ )}+ </>)}</>)}diff --git a/apps/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx b/apps/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsxindex d1a28ddd821..c37ce84e2b9 100644--- a/apps/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx+++ b/apps/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx@@ -1,7 +1,12 @@-import { Button, IconGitBranch } from 'ui'+import {+ Button,+ IconGitBranch,+ TooltipContent_Shadcn_,+ TooltipTrigger_Shadcn_,+ Tooltip_Shadcn_,+} from 'ui'-import { useFlag, useSelectedOrganization } from 'hooks'-import { OPT_IN_TAGS } from 'lib/constants'+import { useFlag, useSelectedProject } from 'hooks'import { useAppStateSnapshot } from 'state/app-state'import BranchingWaitListPopover from './BranchingWaitListPopover'@@ -11,7 +16,7 @@ interface EnableBranchingButtonProps {const EnableBranchingButton = ({ isNewNav = false }: EnableBranchingButtonProps) => {const snap = useAppStateSnapshot()- const selectedOrg = useSelectedOrganization()+ const project = useSelectedProject()const hasAccessToBranching = useFlag<boolean>('branchManagement')@@ -20,13 +25,23 @@ const EnableBranchingButton = ({ isNewNav = false }: EnableBranchingButtonProps)}return (- <Button- type={isNewNav ? 'default' : 'text'}- icon={<IconGitBranch strokeWidth={1.5} />}- onClick={() => snap.setShowEnableBranchingModal(true)}- >- Enable branching- </Button>+ <Tooltip_Shadcn_>+ <TooltipTrigger_Shadcn_ asChild>+ <Button+ type={isNewNav ? 'default' : 'text'}+ icon={<IconGitBranch strokeWidth={1.5} />}+ disabled={project?.status !== 'ACTIVE_HEALTHY'}+ onClick={() => snap.setShowEnableBranchingModal(true)}+ >+ Enable branching+ </Button>+ </TooltipTrigger_Shadcn_>+ {project?.status !== 'ACTIVE_HEALTHY' && (+ <TooltipContent_Shadcn_ side="bottom">+ Unpause your project to enable branching+ </TooltipContent_Shadcn_>+ )}+ </Tooltip_Shadcn_>)}diff --git a/apps/studio/data/config/project-upgrade-eligibility-query.ts b/apps/studio/data/config/project-upgrade-eligibility-query.tsindex 685618c8c6d..0cc5590b687 100644--- a/apps/studio/data/config/project-upgrade-eligibility-query.ts+++ b/apps/studio/data/config/project-upgrade-eligibility-query.ts@@ -1,9 +1,10 @@import { useQuery, UseQueryOptions } from '@tanstack/react-query'-import { get } from 'lib/common/fetch'-import { API_ADMIN_URL } from 'lib/constants'-import { configKeys } from './keys'+import { get } from 'data/fetchers'import type { ResponseError } from 'types'+import { configKeys } from './keys'+import { useProjectByRef } from 'hooks'+import { PROJECT_STATUS } from 'lib/constants'export type ProjectUpgradeEligibilityVariables = { projectRef?: string }export type ProjectUpgradeEligibilityResponse = {@@ -24,11 +25,12 @@ export async function getProjectUpgradeEligibility() {if (!projectRef) throw new Error('projectRef is required')- const response = await get(`${API_ADMIN_URL}/projects/${projectRef}/upgrade/eligibility`, {- signal,+ const { data, error } = await get('/v1/projects/{ref}/upgrade/eligibility', {+ params: { path: { ref: projectRef } },})- if (response.error) throw response.error- return response as ProjectUpgradeEligibilityResponse++ if (error) throw error+ return data as ProjectUpgradeEligibilityResponse}export type ProjectUpgradeEligibilityData = Awaited<ReturnType<typeof getProjectUpgradeEligibility>>@@ -40,9 +42,18 @@ export const useProjectUpgradeEligibilityQuery = <TData = ProjectUpgradeEligibilenabled = true,...options}: UseQueryOptions<ProjectUpgradeEligibilityData, ProjectUpgradeEligibilityError, TData> = {}-) =>- useQuery<ProjectUpgradeEligibilityData, ProjectUpgradeEligibilityError, TData>(+) => {+ const project = useProjectByRef(projectRef)+ return useQuery<ProjectUpgradeEligibilityData, ProjectUpgradeEligibilityError, TData>(configKeys.upgradeEligibility(projectRef),({ signal }) => getProjectUpgradeEligibility({ projectRef }, signal),- { enabled: enabled && typeof projectRef !== 'undefined', ...options }+ {+ enabled:+ enabled &&+ project !== undefined &&+ project.status !== PROJECT_STATUS.INACTIVE &&+ typeof projectRef !== 'undefined',+ ...options,+ })+}