import { useQueryClient } from '@tanstack/react-query' import Link from 'next/link' import { useRouter } from 'next/router' import { useState } from 'react' import { Alert, Button, Form, IconAlertCircle, IconExternalLink, IconPackage, Listbox, Modal, } from 'ui' import { useParams } from 'common/hooks' import InformationBox from 'components/ui/InformationBox' import { useProjectUpgradeEligibilityQuery } from 'data/config/project-upgrade-eligibility-query' import { useProjectUpgradeMutation } from 'data/projects/project-upgrade-mutation' import { setProjectStatus } from 'data/projects/projects-query' import { useStore } from 'hooks' import { PROJECT_STATUS } from 'lib/constants' import { BREAKING_CHANGES } from './ProjectUpgradeAlert.constants' const ProjectUpgradeAlert = () => { const router = useRouter() const { ui } = useStore() const { ref } = useParams() const queryClient = useQueryClient() const [showUpgradeModal, setShowUpgradeModal] = useState(false) const formId = 'project-upgrade-form' const { data } = useProjectUpgradeEligibilityQuery({ projectRef: ref }) const currentPgVersion = (data?.current_app_version ?? '').split('supabase-postgres-')[1] const latestPgVersion = (data?.latest_app_version ?? '').split('supabase-postgres-')[1] const initialValues = { version: data?.target_upgrade_versions?.[0]?.postgres_version ?? 0 } const { mutate: upgradeProject, isLoading: isUpgrading } = useProjectUpgradeMutation({ onSuccess: (res, variables) => { setProjectStatus(queryClient, variables.ref, PROJECT_STATUS.UPGRADING) ui.setNotification({ category: 'success', message: 'Upgrading project' }) router.push(`/project/${variables.ref}?upgradeInitiated=true`) }, }) const onConfirmUpgrade = async (values: any) => { if (!ref) return ui.setNotification({ category: 'error', message: 'Project ref not found' }) upgradeProject({ ref, target_version: values.version }) } return ( <> } variant="success" title="Your project can be upgraded to the latest version of Postgres" >

The latest version of Postgres ({latestPgVersion}) is available for your project.

setShowUpgradeModal(false)} header={

Upgrade Postgres

} >
{({ values }: { values: any }) => { const selectedVersion = (data?.target_upgrade_versions ?? []).find( (x) => x.postgres_version === values.version ) return ( <>

All services, including Auth, Rest, and Extensions will be upgraded. This action cannot be undone.

{(data?.potential_breaking_changes ?? []).length > 0 && ( } title="There will be breaking changes involved with the upgrade" description={
    {data?.potential_breaking_changes.map((reason) => { const change = (BREAKING_CHANGES as any)[reason] if (change !== undefined) return (
  • {change.title}

    This update has breaking changes. Read more here

  • ) else return null })}
} /> )} Upgrades will take a few minutes depending on the size of your database. It is advised to upgrade at a time when there will be minimal impact for your application {data?.target_upgrade_versions.map((version) => ( {version.postgres_version} ( {version.app_version.split('supabase-postgres-')[1]}) ))}
) }}
) } export default ProjectUpgradeAlert