Skip to content

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

DB upgrades

Joshen Lime7316c05a2ac
diff --git a/package-lock.json b/package-lock.json
index dbf8afff773..1882764d4ba 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -10276,9 +10276,9 @@
}
},
"node_modules/@supabase/shared-types": {
- "version": "0.1.31",
- "resolved": "https://registry.npmjs.org/@supabase/shared-types/-/shared-types-0.1.31.tgz",
- "integrity": "sha512-xC4nnUfRUUbQsEH+62bxwf10G7lt4mS0mIq3rM/Yw3MJ0SUToSxIuRTd115GfvFjx5HPbFLJFNVSn8p8njvLaQ=="
+ "version": "0.1.41",
+ "resolved": "https://registry.npmjs.org/@supabase/shared-types/-/shared-types-0.1.41.tgz",
+ "integrity": "sha512-qP1N39xRhi00L6g0FYJCWKAbPQbiVsMP/E3y5zdivOiL2VUFkbLKXYfvzzwhGj3eKdr7O/N/2VtZXWXm+DCx0g=="
},
"node_modules/@supabase/storage-js": {
"version": "2.3.0",
@@ -38712,7 +38712,7 @@
"@stripe/react-stripe-js": "^1.7.0",
"@stripe/stripe-js": "^1.25.0",
"@supabase/react-data-grid": "^7.1.0-beta.7",
- "@supabase/shared-types": "^0.1.29",
+ "@supabase/shared-types": "^0.1.40",
"@supabase/supabase-js": "^2.8.0",
"@tanstack/react-query": "^4.22.0",
"@tanstack/react-query-devtools": "^4.22.0",
@@ -46189,7 +46189,7 @@
"@sinclair/typebox": "^0.25.1",
"pg": "^8.7.1",
"pg-format": "^1.0.4",
- "pgsql-parser": "13.4.0",
+ "pgsql-parser": "^13.3.0",
"postgres-array": "^3.0.1",
"prettier": "^2.6.0",
"prettier-plugin-sql": "^0.12.1"
@@ -46228,9 +46228,9 @@
}
},
"@supabase/shared-types": {
- "version": "0.1.31",
- "resolved": "https://registry.npmjs.org/@supabase/shared-types/-/shared-types-0.1.31.tgz",
- "integrity": "sha512-xC4nnUfRUUbQsEH+62bxwf10G7lt4mS0mIq3rM/Yw3MJ0SUToSxIuRTd115GfvFjx5HPbFLJFNVSn8p8njvLaQ=="
+ "version": "0.1.41",
+ "resolved": "https://registry.npmjs.org/@supabase/shared-types/-/shared-types-0.1.41.tgz",
+ "integrity": "sha512-qP1N39xRhi00L6g0FYJCWKAbPQbiVsMP/E3y5zdivOiL2VUFkbLKXYfvzzwhGj3eKdr7O/N/2VtZXWXm+DCx0g=="
},
"@supabase/storage-js": {
"version": "2.3.0",
@@ -65446,7 +65446,7 @@
"@stripe/stripe-js": "^1.25.0",
"@supabase/postgres-meta": "^0.60.7",
"@supabase/react-data-grid": "^7.1.0-beta.7",
- "@supabase/shared-types": "^0.1.29",
+ "@supabase/shared-types": "^0.1.40",
"@supabase/supabase-js": "^2.8.0",
"@tailwindcss/typography": "^0.5.2",
"@tanstack/react-query": "^4.22.0",
diff --git a/studio/components/interfaces/Settings/General/Infrastructure/Infrastructure.tsx b/studio/components/interfaces/Settings/General/Infrastructure/Infrastructure.tsx
index bd21e2a3bcc..11558390063 100644
--- a/studio/components/interfaces/Settings/General/Infrastructure/Infrastructure.tsx
+++ b/studio/components/interfaces/Settings/General/Infrastructure/Infrastructure.tsx
@@ -2,7 +2,7 @@ import { FC } from 'react'
import { Input } from 'ui'
import { observer } from 'mobx-react-lite'
-import { useStore } from 'hooks'
+import { useFlag, useParams, useStore } from 'hooks'
import { PRICING_TIER_PRODUCT_IDS } from 'lib/constants'
import {
FormHeader,
@@ -11,16 +11,26 @@ import {
FormSectionLabel,
FormSectionContent,
} from 'components/ui/Forms'
+import ProjectUpgradeAlert from './ProjectUpgradeAlert'
import PauseProjectButton from './PauseProjectButton'
import RestartServerButton from './RestartServerButton'
+import { useProjectSubscriptionQuery } from 'data/subscriptions/project-subscription-query'
+import { useProjectUpgradeEligibilityQuery } from 'data/config/project-upgrade-eligibility-query'
interface Props {}
const Infrastructure: FC<Props> = ({}) => {
const { ui } = useStore()
+ const { ref } = useParams()
const project = ui.selectedProject
- const isFreeProject = project?.subscription_tier === PRICING_TIER_PRODUCT_IDS.FREE
+ const { data: subscription } = useProjectSubscriptionQuery({ projectRef: ref })
+ const isFreeProject = subscription?.tier.supabase_prod_id === PRICING_TIER_PRODUCT_IDS.FREE
+
+ const { data, isLoading } = useProjectUpgradeEligibilityQuery({ projectRef: ref })
+ const currentPgVersion = (data?.current_app_version ?? '').split('supabase-postgres-')[1]
+
+ const showDbUpgrades = useFlag('databaseUpgrades')
return (
<div>
@@ -67,6 +77,13 @@ const Infrastructure: FC<Props> = ({}) => {
<Input readOnly disabled value={project?.region} label="Region" />
</FormSectionContent>
</FormSection>
+
+ <FormSection header={<FormSectionLabel>Postgres</FormSectionLabel>}>
+ <FormSectionContent loading={isLoading}>
+ <Input readOnly disabled value={currentPgVersion} label="Current version" />
+ {data?.eligible && showDbUpgrades && <ProjectUpgradeAlert />}
+ </FormSectionContent>
+ </FormSection>
</FormPanel>
</div>
)
diff --git a/studio/components/interfaces/Settings/General/Infrastructure/ProjectUpgradeAlert/ProjectUpgradeAlert.constants.ts b/studio/components/interfaces/Settings/General/Infrastructure/ProjectUpgradeAlert/ProjectUpgradeAlert.constants.ts
new file mode 100644
index 00000000000..e36276103e7
--- /dev/null
+++ b/studio/components/interfaces/Settings/General/Infrastructure/ProjectUpgradeAlert/ProjectUpgradeAlert.constants.ts
@@ -0,0 +1,19 @@
+// [Joshen] TODO: Change the keys to enums from shared-types when ready
+
+export const BREAKING_CHANGES = {
+ 'postgrest-v10': {
+ title: 'Postgrest will be upgraded to V10',
+ url: 'https://postgrest.org/en/stable/releases/v10.0.0.html#breaking-changes',
+ },
+}
+
+export const MANUAL_INTERVENTIONS = {
+ project_unsupported_too_old: {
+ title: 'Project is too old',
+ description: '',
+ },
+ project_kps_enabled: {
+ title: 'Project has KPS enabled',
+ description: '',
+ },
+}
diff --git a/studio/components/interfaces/Settings/General/Infrastructure/ProjectUpgradeAlert/ProjectUpgradeAlert.tsx b/studio/components/interfaces/Settings/General/Infrastructure/ProjectUpgradeAlert/ProjectUpgradeAlert.tsx
new file mode 100644
index 00000000000..47574854833
--- /dev/null
+++ b/studio/components/interfaces/Settings/General/Infrastructure/ProjectUpgradeAlert/ProjectUpgradeAlert.tsx
@@ -0,0 +1,175 @@
+import Link from 'next/link'
+import { useRouter } from 'next/router'
+import { FC, useState } from 'react'
+import {
+ Alert,
+ Button,
+ Form,
+ Modal,
+ IconPackage,
+ Listbox,
+ IconAlertCircle,
+ IconExternalLink,
+} from 'ui'
+
+import { useParams, useStore } from 'hooks'
+import { post } from 'lib/common/fetch'
+import { API_ADMIN_URL, PROJECT_STATUS } from 'lib/constants'
+import InformationBox from 'components/ui/InformationBox'
+import { BREAKING_CHANGES } from './ProjectUpgradeAlert.constants'
+import { useProjectUpgradeEligibilityQuery } from 'data/config/project-upgrade-eligibility-query'
+
+interface Props {}
+
+const ProjectUpgradeAlert: FC<Props> = ({}) => {
+ const router = useRouter()
+ const { app, ui } = useStore()
+ const { ref } = useParams()
+ 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 onConfirmUpgrade = async (values: any, { setSubmitting }: any) => {
+ setSubmitting(true)
+
+ const res = await post(`${API_ADMIN_URL}/projects/${ref}/upgrade`, {
+ target_version: values.version,
+ })
+ if (res.error) {
+ ui.setNotification({
+ category: 'error',
+ error: res.error,
+ message: `Failed to upgrade: ${res.error.message}`,
+ })
+ setSubmitting(false)
+ } else {
+ const projectId = ui.selectedProject?.id
+ if (projectId !== undefined) {
+ app.onProjectStatusUpdated(projectId, PROJECT_STATUS.UPGRADING)
+ ui.setNotification({ category: 'success', message: 'Upgrading project' })
+ router.push(`/project/${ref}?upgradeInitiated=true`)
+ }
+ }
+ }
+
+ return (
+ <>
+ <Alert
+ icon={<IconPackage className="text-brand-900" strokeWidth={1.5} />}
+ variant="success"
+ title="Your project can be upgraded to the latest version of Postgres"
+ >
+ <p className="mb-3">
+ The latest version of Postgres ({latestPgVersion}) is available for your project.
+ </p>
+ <Button size="tiny" type="primary" onClick={() => setShowUpgradeModal(true)}>
+ Upgrade project
+ </Button>
+ </Alert>
+ <Modal
+ hideFooter
+ visible={showUpgradeModal}
+ onCancel={() => setShowUpgradeModal(false)}
+ header={<h3>Upgrade project's Postgres</h3>}
+ >
+ <Form id={formId} initialValues={initialValues} onSubmit={onConfirmUpgrade}>
+ {({ values, isSubmitting }: { values: any; isSubmitting: boolean }) => {
+ return (
+ <>
+ <div className="py-6">
+ <Modal.Content>
+ <div className="space-y-4">
+ <p className="text-sm">
+ All of your project's services, such as GoTrue, PostgREST, Supautils, and
+ all database extensions will be upgraded as well, and this action cannot be
+ undone.
+ </p>
+ {(data?.potential_breaking_changes ?? []).length > 0 && (
+ <InformationBox
+ icon={<IconAlertCircle strokeWidth={2} />}
+ title="There will be breaking changes involved with the upgrade"
+ description={
+ <ul className="list-disc pl-4">
+ {data?.potential_breaking_changes.map((reason) => {
+ const change = (BREAKING_CHANGES as any)[reason]
+ if (change !== undefined)
+ return (
+ <li key={reason}>
+ <p className="text-scale-1200">{change.title}</p>
+ <p className="flex items-center space-x-1">
+ <span>
+ Breaking changes with this version are highlighted{' '}
+ </span>
+ <Link href={change.url}>
+ <a className="text-brand-900 opacity-90 flex items-center space-x-1">
+ <span>here</span>
+ <IconExternalLink size="tiny" strokeWidth={2} />
+ </a>
+ </Link>
+ </p>
+ </li>
+ )
+ else return null
+ })}
+ </ul>
+ }
+ />
+ )}
+ <Alert
+ withIcon
+ variant="warning"
+ title="Your project will be offline while the upgrade is in progress"
+ >
+ 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
+ </Alert>
+ <Listbox
+ id="version"
+ name="version"
+ label="Select the version of Postgres to upgrade to"
+ descriptionText={`Your project's Postgres will be upgraded from ${currentPgVersion} to ${values.version}`}
+ >
+ {data?.target_upgrade_versions.map((version) => (
+ <Listbox.Option
+ key={version.postgres_version}
+ value={version.postgres_version}
+ label={`${version.postgres_version} (${
+ version.app_version.split('supabase-postgres-')[1]
+ })`}
+ >
+ {version.postgres_version} (
+ {version.app_version.split('supabase-postgres-')[1]})
+ </Listbox.Option>
+ ))}
+ </Listbox>
+ </div>
+ </Modal.Content>
+ </div>
+ <div className="flex items-center space-x-2 justify-end px-4 py-4 border-t">
+ <Button
+ type="default"
+ onClick={() => setShowUpgradeModal(false)}
+ disabled={isSubmitting}
+ >
+ Cancel
+ </Button>
+ <Button htmlType="submit" disabled={isSubmitting} loading={isSubmitting}>
+ Confirm upgrade
+ </Button>
+ </div>
+ </>
+ )
+ }}
+ </Form>
+ </Modal>
+ </>
+ )
+}
+
+export default ProjectUpgradeAlert
diff --git a/studio/components/interfaces/Settings/General/Infrastructure/ProjectUpgradeAlert/index.ts b/studio/components/interfaces/Settings/General/Infrastructure/ProjectUpgradeAlert/index.ts
new file mode 100644
index 00000000000..74c03a0bc01
--- /dev/null
+++ b/studio/components/interfaces/Settings/General/Infrastructure/ProjectUpgradeAlert/index.ts
@@ -0,0 +1,2 @@
+import ProjectUpgradeAlert from './ProjectUpgradeAlert'
+export default ProjectUpgradeAlert
diff --git a/studio/components/interfaces/Support/SupportForm.tsx b/studio/components/interfaces/Support/SupportForm.tsx
index 24ec9a1f014..34dff31cf3f 100644
--- a/studio/components/interfaces/Support/SupportForm.tsx
+++ b/studio/components/interfaces/Support/SupportForm.tsx
@@ -40,7 +40,7 @@ interface Props {
const SupportForm: FC<Props> = ({ setSentCategory }) => {
const { ui, app } = useStore()
const router = useRouter()
- const { ref, subject, category } = router.query
+ const { ref, subject, category, message } = router.query
const uploadButtonRef = useRef()
const enableFreeSupport = useFlag('enableFreeSupport')
@@ -108,7 +108,7 @@ const SupportForm: FC<Props> = ({ setSentCategory }) => {
organizationSlug: initialOrganizationSlug,
library: 'no-library',
subject: subject ?? '',
- message: '',
+ message: message || '',
allowSupportAccess: false,
}
diff --git a/studio/components/layouts/ProjectLayout/ProjectLayout.tsx b/studio/components/layouts/ProjectLayout/ProjectLayout.tsx
index 3def6eaba71..b29149306be 100644
--- a/studio/components/layouts/ProjectLayout/ProjectLayout.tsx
+++ b/studio/components/layouts/ProjectLayout/ProjectLayout.tsx
@@ -115,10 +115,9 @@ const ContentWrapper: FC<ContentWrapperProps> = observer(({ isLoading, children
const requiresDbConnection: boolean = router.pathname !== '/project/[ref]/settings/general'
const requiresPostgrestConnection = !routesToIgnorePostgrestConnection.includes(router.pathname)
+ const isProjectUpgrading = ui.selectedProject?.status === PROJECT_STATUS.UPGRADING
const isProjectRestoring = ui.selectedProject?.status === PROJECT_STATUS.RESTORING
- const isProjectBuilding = [PROJECT_STATUS.COMING_UP, PROJECT_STATUS.RESTORING].includes(
- ui.selectedProject?.status ?? ''
- )
+ const isProjectBuilding = ui.selectedProject?.status === PROJECT_STATUS.COMING_UP
const isProjectPausing = ui.selectedProject?.status === PROJECT_STATUS.GOING_DOWN
const isProjectOffline = ui.selectedProject?.postgrestStatus === 'OFFLINE'
diff --git a/studio/components/layouts/ProjectLayout/UpgradingState/UpgradingState.constants.ts b/studio/components/layouts/ProjectLayout/UpgradingState/UpgradingState.constants.ts
new file mode 100644
index 00000000000..e0423da8708
--- /dev/null
+++ b/studio/components/layouts/ProjectLayout/UpgradingState/UpgradingState.constants.ts
@@ -0,0 +1,52 @@
+import { DatabaseUpgradeProgress } from '@supabase/shared-types/out/events'
+
+export const DATABASE_UPGRADE_MESSAGES = [
+ {
+ key: DatabaseUpgradeProgress.Started,
+ initial: 'Prepare new server',
+ progress: 'Preparing new server',
+ completed: 'Prepared new server',
+ },
+ {
+ key: DatabaseUpgradeProgress.LaunchedUpgradedInstance,
+ initial: 'Prepare new server for migration',
+ progress: 'Preparing new server for migration',
+ completed: 'New server ready for migration',
+ },
+ {
+ key: DatabaseUpgradeProgress.DetachedVolumeFromUpgradedInstance,
+ initial: 'Execute pre-upgrade checks',
+ progress: 'Executing pre-upgrade checks',
+ completed: 'Completed pre-upgrade checks',
+ },
+ {
+ key: DatabaseUpgradeProgress.AttachedVolumeToOriginalInstance,
+ initial: 'Shut down API services',
+ progress: 'Shutting down API services',
+ completed: 'Completed shutting down API services',
+ },
+ {
+ key: DatabaseUpgradeProgress.InitiatedDataUpgrade,
+ initial: 'Migrate to new database',
+ progress: 'Migrating to new database',
+ completed: 'Completed migration to new database',
+ },
+ {
+ key: DatabaseUpgradeProgress.CompletedDataUpgrade,
+ initial: 'Execute database migration',
+ progress: 'Executing database migration',
+ completed: 'Completed database migration',
+ },
+ {
+ key: DatabaseUpgradeProgress.DetachedVolumeFromOriginalInstance,
+ initial: 'Update database extensions',
+ progress: 'Updating database extensions',
+ completed: 'Updated database extensions',
+ },
+ {
+ key: DatabaseUpgradeProgress.AttachedVolumeToUpgradedInstance,
+ initial: 'Optimize database',
+ progress: 'Optimizing database',
+ completed: 'Completed optimization of database',
+ },
+]
diff --git a/studio/components/layouts/ProjectLayout/UpgradingState/UpgradingState.tsx b/studio/components/layouts/ProjectLayout/UpgradingState/UpgradingState.tsx
new file mode 100644
index 00000000000..31328295eac
--- /dev/null
+++ b/studio/components/layouts/ProjectLayout/UpgradingState/UpgradingState.tsx
@@ -0,0 +1,267 @@
+import dayjs from 'dayjs'
+import Link from 'next/link'
+import { useState, useEffect } from 'react'
+import * as Tooltip from '@radix-ui/react-tooltip'
+import {
+ Button,
+ IconCircle,
+ IconCheckCircle,
+ IconSettings,
+ IconAlertCircle,
+ IconLoader,
+ IconCheck,
+ IconMaximize2,
+ IconMinimize2,
+} from 'ui'
+import { DatabaseUpgradeStatus } from '@supabase/shared-types/out/events'
+
+import { useParams, useStore } from 'hooks'
+import { DATABASE_UPGRADE_MESSAGES } from './UpgradingState.constants'
+import { useProjectUpgradingStatusQuery } from 'data/config/project-upgrade-status-query'
+
+const UpgradingState = () => {
+ const { ui } = useStore()
+ const project = ui.selectedProject
+
+ // [Joshen] If routing to this state from ProjectUpgradeAlert, give it a few seconds before starting
+ // to poll the upgrade status endpoint as the job is async and might not be immediately updated.
+ const { upgradeInitiated } = useParams()
+ const [isInitialized, setIsInitialized] = useState(upgradeInitiated !== 'true')
+
+ useEffect(() => {
+ if (!isInitialized) setTimeout(() => setIsInitialized(true), 5000)
+ }, [])
+
+ if (isInitialized) {
+ return <UpgradingPollingState />
+ } else {
+ return (
+ <div className="mx-auto my-16 w-full max-w-7xl space-y-16">
+ <div className="mx-6 space-y-16">
+ <div className="flex flex-col space-y-4 lg:flex-row lg:items-center lg:space-y-0 lg:space-x-6">
+ <h1 className="text-3xl">{project?.name}</h1>
+ </div>
+ <div className="mx-auto mt-8 mb-16 w-full max-w-7xl">
+ <div className="flex h-[500px] items-center justify-center rounded border border-scale-400 bg-scale-300 p-8">
+ <div className="grid w-[480px] gap-4">
+ <div className="relative mx-auto max-w-[300px]">
+ <div className="absolute flex h-full w-full items-center justify-center">
+ <IconSettings className="animate-spin" size={20} strokeWidth={2} />
+ </div>
+ <IconCircle className="text-scale-900" size={50} strokeWidth={1.5} />
+ </div>
+ <div className="space-y-2">
+ <p className="text-center">Upgrading in progress</p>
+ <p className="text-center text-sm text-scale-1100">
+ Upgrades can take from a few minutes up to several hours depending on the size
+ of your database. Your project will be offline while it is being upgraded.
+ </p>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ )
+ }
+}
+
+const UpgradingPollingState = () => {
+ const { ref } = useParams()
+ const { app, ui, meta } = useStore()
+ const [loading, setLoading] = useState(false)
+ const [isExpanded, setIsExpanded] = useState(false)
+ const { data } = useProjectUpgradingStatusQuery({ projectRef: ref })
+
+ const project = ui.selectedProject
+ const { initiated_at, status, progress, target_version, error } =
+ data?.databaseUpgradeStatus ?? {}
+ const progressStage = Number((progress || '').split('_')[0])
+
+ const isFailed = status === DatabaseUpgradeStatus.Failed
+ const isCompleted = status === DatabaseUpgradeStatus.Upgraded
+
+ const initiatedAt = dayjs(initiated_at ?? 0).format('DD MMM YYYY HH:mm:ss (ZZ)')
+ const initiatedAtUTC = dayjs(initiated_at ?? 0)
+ .utc()
+ .format('DD MMM YYYY HH:mm:ss')
+
+ const refetchProjectDetails = async () => {
+ setLoading(true)
+ await app.projects.fetchDetail(project?.ref ?? '', (project) => meta.setProjectDetails(project))
+ }
+
+ const subject = 'Upgrade%20failed%20for%20project'
+ const message = `Upgrade information:%0A• Initiated at: ${initiated_at}%0A• Target Version: ${target_version}%0A• Error: ${error}`
+
+ return (
+ <div className="mx-auto my-16 w-full max-w-7xl space-y-16">
+ <div className="mx-6 space-y-16">
+ <div className="flex flex-col space-y-4 lg:flex-row lg:items-center lg:space-y-0 lg:space-x-6">
+ <h1 className="text-3xl">{project?.name}</h1>
+ </div>
+ <div className="mx-auto mt-8 mb-16 w-full max-w-7xl">
+ <div className="flex h-[500px] items-center justify-center rounded border border-scale-400 bg-scale-300 p-8">
+ {isCompleted ? (
+ <div className="grid gap-4">
+ <div className="relative mx-auto max-w-[300px]">
+ <IconCheckCircle className="text-brand-900" size={40} strokeWidth={1.5} />
+ </div>
+ <div className="space-y-2">
+ <p className="text-center">Upgrade completed!</p>
+ <p className="mt-4 text-center text-sm text-scale-1100 w-[300px] mx-auto">
+ Your project has been successfully upgraded to Postgres {target_version} and is
+ now back online.
+ </p>
+ </div>
+ <div className="mx-auto">
+ <Button loading={loading} disabled={loading} onClick={refetchProjectDetails}>
+ Return to project
+ </Button>
+ </div>
+ </div>
+ ) : isFailed ? (
+ <div className="grid gap-4">
+ <div className="relative mx-auto max-w-[300px]">
+ <IconAlertCircle className="text-amber-900" size={40} strokeWidth={1.5} />
+ </div>
+ <div className="space-y-2">
+ <p className="text-center">We ran into an issue while upgrading your project</p>
+ <p className="mt-4 text-center text-sm text-scale-1100 w-[450px] mx-auto">
+ Your project is back online and its data is not affected. Please reach out to us
+ via our support form for assistance with the upgrade.
+ </p>
+ </div>
+ <div className="flex items-center mx-auto space-x-2">
+ <Link
+ href={`/support/new?category=Database_unresponsive&ref=${ref}&subject=${subject}&message=${message}`}
+ >
+ <a target="_blank">
+ <Button type="default">Contact support</Button>
+ </a>
+ </Link>
+ <Button loading={loading} disabled={loading} onClick={refetchProjectDetails}>
+ Return to project
+ </Button>
+ </div>
+ </div>
+ ) : (
+ <div className="grid w-[480px] gap-4">
+ <div className="relative mx-auto max-w-[300px]">
+ <div className="absolute flex h-full w-full items-center justify-center">
+ <IconSettings className="animate-spin" size={20} strokeWidth={2} />
+ </div>
+ <IconCircle className="text-scale-900" size={50} strokeWidth={1.5} />
+ </div>
+ <div className="space-y-2">
+ <p className="text-center">Upgrading in progress</p>
+ <p className="text-center text-sm text-scale-1100">
+ Upgrades can take from a few minutes up to several hours depending on the size
+ of your database. Your project will be offline while it is being upgraded.
+ </p>
+
+ <div
+ className="!mt-4 !mb-2 py-3 px-4 transition-all overflow-hidden border rounded relative"
+ style={{ maxHeight: isExpanded ? '500px' : '110px' }}
+ >
+ {isExpanded ? (
+ <IconMinimize2
+ size="tiny"
+ strokeWidth={2}
+ className="absolute top-3 right-3 cursor-pointer z-10"
+ onClick={() => setIsExpanded(false)}
+ />
+ ) : (
+ <IconMaximize2
+ size="tiny"
+ strokeWidth={2}
+ className="absolute top-3 right-3 cursor-pointer z-10"
+ onClick={() => setIsExpanded(true)}
+ />
+ )}
+ <div
+ className="space-y-2 transition-all"
+ style={{
+ translate: isExpanded
+ ? '0px 0px'
+ : `0px ${
+ (progressStage - 2 <= 0
+ ? 0
+ : progressStage > 6
+ ? 5
+ : progressStage - 2) * -28
+ }px`,
+ }}
+ >
+ {DATABASE_UPGRADE_MESSAGES.map((message, idx: number) => {
+ const isCurrent = message.key === progress
+ const isCompleted = progressStage > idx
+ return (
+ <div key={message.key} className="flex items-center space-x-4">
+ {isCurrent ? (
+ <div className="h-5 w-5 flex items-center justify-center rounded-full">
+ <IconLoader
+ size={20}
+ className="animate-spin text-scale-1100"
+ strokeWidth={2}
+ />
+ </div>
+ ) : isCompleted ? (
+ <div className="h-5 w-5 flex items-center justify-center rounded-full border bg-brand-800 border-brand-700">
+ <IconCheck size={12} className="text-white" strokeWidth={2} />
+ </div>
+ ) : (
+ <div className="h-5 w-5 flex items-center justify-center border rounded-full bg-scale-600" />
+ )}
+ <p
+ className={`text-sm ${
+ isCurrent
+ ? 'text-scale-1200'
+ : isCompleted
+ ? 'text-scale-1100'
+ : 'text-scale-1000'
+ } hover:text-scale-1200 transition`}
+ >
+ {isCurrent
+ ? message.progress
+ : isCompleted
+ ? message.completed
+ : message.initial}
+ </p>
+ </div>
+ )
+ })}
+ </div>
+ </div>
+
+ {initiated_at !== undefined && (
+ <Tooltip.Root delayDuration={0}>
+ <Tooltip.Trigger className="w-full">
+ <p className="text-center text-sm text-scale-1000">
+ Started on: {initiatedAtUTC} (UTC)
+ </p>
+ </Tooltip.Trigger>
+ <Tooltip.Content side="bottom">
+ <Tooltip.Arrow className="radix-tooltip-arrow" />
+ <div
+ className={[
+ 'rounded bg-scale-100 py-1 px-2 leading-none shadow', // background
+ 'border border-scale-200 ', //border
+ ].join(' ')}
+ >
+ <span className="text-xs text-scale-1200">{initiatedAt}</span>
+ </div>
+ </Tooltip.Content>
+ </Tooltip.Root>
+ )}
+ </div>
+ </div>
+ )}
+ </div>
+ </div>
+ </div>
+ </div>
+ )
+}
+
+export default UpgradingState
diff --git a/studio/components/layouts/ProjectLayout/UpgradingState/index.ts b/studio/components/layouts/ProjectLayout/UpgradingState/index.ts
new file mode 100644
index 00000000000..eb515bf7666
--- /dev/null
+++ b/studio/components/layouts/ProjectLayout/UpgradingState/index.ts
@@ -0,0 +1,2 @@
+import UpgradingState from './UpgradingState'
+export default UpgradingState
diff --git a/studio/components/ui/ProjectUpgradeFailedBanner.tsx b/studio/components/ui/ProjectUpgradeFailedBanner.tsx
new file mode 100644
index 00000000000..5e23e6634e2
--- /dev/null
+++ b/studio/components/ui/ProjectUpgradeFailedBanner.tsx
@@ -0,0 +1,66 @@
+import dayjs from 'dayjs'
+import Link from 'next/link'
+import { useState } from 'react'
+import { Alert, Button, IconX } from 'ui'
+import { useParams } from 'hooks'
+import { useProjectUpgradingStatusQuery } from 'data/config/project-upgrade-status-query'
+import { DatabaseUpgradeStatus } from '@supabase/shared-types/out/events'
+
+// [Joshen] Think twice about the category though - it doesn't correspond
+
+const ProjectUpgradeFailedBanner = () => {
+ const { ref } = useParams()
+ const { data } = useProjectUpgradingStatusQuery({ projectRef: ref })
+ const { target_version, status, initiated_at, error } = data?.databaseUpgradeStatus ?? {}
+
+ const key = `supabase-upgrade-${ref}-${initiated_at}`
+ const isAcknowledged = localStorage.getItem(key) === 'true'
+ const [showMessage, setShowMessage] = useState(!isAcknowledged)
+
+ const isFailed = status === DatabaseUpgradeStatus.Failed
+ const initiatedAtUTC = dayjs(initiated_at ?? 0)
+ .utc()
+ .format('DD MMM YYYY HH:mm:ss')
+
+ const subject = 'Upgrade%20failed%20for%20project'
+ const message = `Upgrade information:%0A• Initiated at: ${initiated_at}%0A• Target Version: ${target_version}%0A• Error: ${error}`
+
+ const acknowledgeMessage = () => {
+ setShowMessage(false)
+ localStorage.setItem(key, 'true')
+ }
+
+ if (!isFailed || !showMessage) return null
+
+ return (
+ <div className="max-w-7xl">
+ <Alert
+ withIcon
+ variant={'warning'}
+ title={`Postgres version upgrade to ${target_version} was not successful (Initiated at ${initiatedAtUTC} UTC)`}
+ actions={
+ <div className="flex h-full items-center space-x-4">
+ <Link
+ href={`/support/new?category=Database_unresponsive&ref=${ref}&subject=${subject}&message=${message}`}
+ >
+ <a target="_blank">
+ <Button type="default">Contact support</Button>
+ </a>
+ </Link>
+ <Button
+ type="text"
+ className="px-1"
+ icon={<IconX size={16} strokeWidth={1.5} />}
+ onClick={() => acknowledgeMessage()}
+ />
+ </div>
+ }
+ >
+ Your project and its data are not affected. Please reach out to us via our support form for
+ assistance with the upgrade.
+ </Alert>
+ </div>
+ )
+}
+
+export default ProjectUpgradeFailedBanner
diff --git a/studio/components/ui/SparkBar.tsx b/studio/components/ui/SparkBar.tsx
index d2385ef3dfe..a4f45c1ce30 100644
--- a/studio/components/ui/SparkBar.tsx
+++ b/studio/components/ui/SparkBar.tsx
@@ -3,7 +3,7 @@ import { FC } from 'react'
interface Props {
value: number
max?: number
- type?: string
+ type?: 'horizontal' | 'vertical'
labelTop?: string
labelBottom?: string
barClass?: string
@@ -16,7 +16,7 @@ const SparkBar: FC<Props> = ({
value = 0,
barClass = '',
bgClass = '',
- type = '',
+ type = 'vertical',
borderClass = '',
labelBottom = '',
labelTop = '',
@@ -30,7 +30,9 @@ const SparkBar: FC<Props> = ({
<div className="flex flex-col w-full">
{hasLabels && (
<div className="flex align-baseline justify-between pb-1 space-x-8">
- <span className="text-scale-1200 text-sm truncate">{labelBottom}</span>
+ <span className="text-scale-1200 text-sm truncate capitalize-sentence">
+ {labelBottom}
+ </span>
<span className="text-scale-1100 text-sm tabular-nums">{labelTop}</span>
</div>
)}
@@ -40,7 +42,7 @@ const SparkBar: FC<Props> = ({
} ${borderClass ? borderClass : 'border-none'}`}
>
<div
- className={`absolute rounded inset-x-0 bottom-0 h-1 ${barClass}`}
+ className={`absolute rounded inset-x-0 bottom-0 h-1 ${barClass} transition-all`}
style={{ width: widthCss }}
></div>
</div>
diff --git a/studio/data/config/keys.ts b/studio/data/config/keys.ts
index 1f0b8701751..b6776176300 100644
--- a/studio/data/config/keys.ts
+++ b/studio/data/config/keys.ts
@@ -5,4 +5,8 @@ export const configKeys = {
jwtSecretUpdatingStatus: (projectRef: string | undefined) =>
['projects', projectRef, 'jwt-secret-updating-status'] as const,
storage: (projectRef: string | undefined) => ['projects', projectRef, 'storage'] as const,
+ upgradeEligibility: (projectRef: string | undefined) =>
+ ['projects', projectRef, 'upgrade-eligibility'] as const,
+ upgradeStatus: (projectRef: string | undefined) =>
+ ['projects', projectRef, 'upgrade-status'] as const,
}
diff --git a/studio/data/config/project-upgrade-eligibility-query.ts b/studio/data/config/project-upgrade-eligibility-query.ts
new file mode 100644
index 00000000000..98e17eb287a
--- /dev/null
+++ b/studio/data/config/project-upgrade-eligibility-query.ts
@@ -0,0 +1,59 @@
+import { useCallback } from 'react'
+import { useQuery, useQueryClient, UseQueryOptions } from '@tanstack/react-query'
+
+import { get } from 'lib/common/fetch'
+import { API_ADMIN_URL } from 'lib/constants'
+import { configKeys } from './keys'
+
+export type ProjectUpgradeEligibilityVariables = { projectRef?: string }
+export type ProjectUpgradeEligibilityResponse = {
+ eligible: boolean
+ current_app_version: string
+ latest_app_version: string
+ target_upgrade_versions: { postgres_version: number; app_version: string }[]
+ requires_manual_intervention: string | null
+ potential_breaking_changes: string[]
+}
+
+export async function getProjectUpgradeEligibility(
+ { projectRef }: ProjectUpgradeEligibilityVariables,
+ signal?: AbortSignal
+) {
+ if (!projectRef) throw new Error('projectRef is required')
+
+ const response = await get(`${API_ADMIN_URL}/projects/${projectRef}/upgrade/eligibility`, {
+ signal,
+ })
+ if (response.error) throw response.error
+ return response as ProjectUpgradeEligibilityResponse
+}
+
+export type ProjectUpgradeEligibilityData = Awaited<ReturnType<typeof getProjectUpgradeEligibility>>
+export type ProjectUpgradeEligibilityError = unknown
+
+export const useProjectUpgradeEligibilityQuery = <TData = ProjectUpgradeEligibilityData>(
+ { projectRef }: ProjectUpgradeEligibilityVariables,
+ {
+ enabled = true,
+ ...options
+ }: UseQueryOptions<ProjectUpgradeEligibilityData, ProjectUpgradeEligibilityError, TData> = {}
+) =>
+ useQuery<ProjectUpgradeEligibilityData, ProjectUpgradeEligibilityError, TData>(
+ configKeys.upgradeEligibility(projectRef),
+ ({ signal }) => getProjectUpgradeEligibility({ projectRef }, signal),
+ { enabled: enabled && typeof projectRef !== 'undefined', ...options }
+ )
+
+export const useProjectUpgradeEligibilityPrefetch = ({
+ projectRef,
+}: ProjectUpgradeEligibilityVariables) => {
+ const client = useQueryClient()
+
+ return useCallback(() => {
+ if (projectRef) {
+ client.prefetchQuery(configKeys.upgradeEligibility(projectRef), ({ signal }) =>
+ getProjectUpgradeEligibility({ projectRef }, signal)
+ )
+ }
+ }, [projectRef])
+}
diff --git a/studio/data/config/project-upgrade-status-query.ts b/studio/data/config/project-upgrade-status-query.ts
new file mode 100644
index 00000000000..cf577a8d657
--- /dev/null
+++ b/studio/data/config/project-upgrade-status-query.ts
@@ -0,0 +1,87 @@
+import { useQuery, useQueryClient, UseQueryOptions } from '@tanstack/react-query'
+import {
+ DatabaseUpgradeError,
+ DatabaseUpgradeStatus,
+ DatabaseUpgradeProgress,
+} from '@supabase/shared-types/out/events'
+import { get } from 'lib/common/fetch'
+import { API_ADMIN_URL } from 'lib/constants'
+import { useCallback } from 'react'
+import { configKeys } from './keys'
+
+export type ProjectUpgradingStatusVariables = {
+ projectRef?: string
+}
+
+export type ProjectUpgradingStatusResponse = {
+ databaseUpgradeStatus: {
+ error?: DatabaseUpgradeError
+ progress?: DatabaseUpgradeProgress
+ status: DatabaseUpgradeStatus
+ initiated_at: string
+ target_version: number
+ } | null
+}
+
+export async function getProjectUpgradingStatus(
+ { projectRef }: ProjectUpgradingStatusVariables,
+ signal?: AbortSignal
+) {
+ if (!projectRef) throw new Error('projectRef is required')
+
+ const response = await get(`${API_ADMIN_URL}/projects/${projectRef}/upgrade/status`, { signal })
+ if (response.error) throw response.error
+
+ return response as ProjectUpgradingStatusResponse
+}
+
+export type ProjectUpgradingStatusData = Awaited<ReturnType<typeof getProjectUpgradingStatus>>
+export type ProjectUpgradingStatusError = unknown
+
+export const useProjectUpgradingStatusQuery = <TData = ProjectUpgradingStatusData>(
+ { projectRef }: ProjectUpgradingStatusVariables,
+ {
+ enabled = true,
+ ...options
+ }: UseQueryOptions<ProjectUpgradingStatusData, ProjectUpgradingStatusError, TData> = {}
+) => {
+ const client = useQueryClient()
+
+ return useQuery<ProjectUpgradingStatusData, ProjectUpgradingStatusError, TData>(
+ configKeys.upgradeStatus(projectRef),
+ ({ signal }) => getProjectUpgradingStatus({ projectRef }, signal),
+ {
+ enabled: enabled && typeof projectRef !== 'undefined',
+ refetchInterval(data) {
+ const response = data as unknown as ProjectUpgradingStatusResponse
+ if (!response || response.databaseUpgradeStatus === null) return false
+
+ const interval =
+ response.databaseUpgradeStatus.status === DatabaseUpgradeStatus.Upgrading ? 5000 : false
+ return interval
+ },
+ onSuccess(data) {
+ const response = data as unknown as ProjectUpgradingStatusResponse
+ if (response.databaseUpgradeStatus?.status === DatabaseUpgradeStatus.Upgraded) {
+ client.invalidateQueries(configKeys.upgradeEligibility(projectRef))
+ }
+ },
+ ...options,
+ }
+ )
+}
+
+export const useProjectUpgradingStatusPrefetch = ({
+ projectRef,
+}: ProjectUpgradingStatusVariables) => {
+ const client = useQueryClient()
+
+ //[josheh] need to invalidate the eligibility key
+ return useCallback(() => {
+ if (projectRef) {
+ client.prefetchQuery(configKeys.upgradeStatus(projectRef), ({ signal }) =>
+ getProjectUpgradingStatus({ projectRef }, signal)
+ )
+ }
+ }, [projectRef])
+}
diff --git a/studio/lib/constants/infrastructure.ts b/studio/lib/constants/infrastructure.ts
index 5c4e675ec05..437fff21808 100644
--- a/studio/lib/constants/infrastructure.ts
+++ b/studio/lib/constants/infrastructure.ts
@@ -107,6 +107,7 @@ export const PROJECT_STATUS = {
REMOVED: 'REMOVED',
RESTORING: 'RESTORING',
RESTORATION_FAILED: 'RESTORATION_FAILED',
+ UPGRADING: 'UPGRADING',
}
export const STRIPE_PRODUCT_IDS: { [x: string]: string } = {
diff --git a/studio/package.json b/studio/package.json
index c51eda86ca4..dc6c1024dd9 100644
--- a/studio/package.json
+++ b/studio/package.json
@@ -29,7 +29,7 @@
"@stripe/react-stripe-js": "^1.7.0",
"@stripe/stripe-js": "^1.25.0",
"@supabase/react-data-grid": "^7.1.0-beta.7",
- "@supabase/shared-types": "^0.1.29",
+ "@supabase/shared-types": "^0.1.40",
"@supabase/supabase-js": "^2.8.0",
"@tanstack/react-query": "^4.22.0",
"@tanstack/react-query-devtools": "^4.22.0",
diff --git a/studio/pages/project/[ref]/index.tsx b/studio/pages/project/[ref]/index.tsx
index 1c334d1e856..38d0c25de3e 100644
--- a/studio/pages/project/[ref]/index.tsx
+++ b/studio/pages/project/[ref]/index.tsx
@@ -9,6 +9,7 @@ import { CLIENT_LIBRARIES, EXAMPLE_PROJECTS } from 'components/interfaces/Home/H
import ProjectUsageSection from 'components/interfaces/Home/ProjectUsageSection'
import ProjectPausedState from 'components/layouts/ProjectLayout/ProjectPausedState'
import OveragesBanner from 'components/ui/OveragesBanner/OveragesBanner'
+import ProjectUpgradeFailedBanner from 'components/ui/ProjectUpgradeFailedBanner'
const Home: NextPageWithLayout = () => {
const { ui } = useStore()
@@ -31,6 +32,7 @@ const Home: NextPageWithLayout = () => {
<div className="mx-6">
{/* [Joshen TODO] Temporarily hidden until usage endpoint is sorted out */}
{/* {projectTier !== undefined && <OveragesBanner minimal tier={projectTier} />} */}
+ <ProjectUpgradeFailedBanner />
</div>
{project?.status === PROJECT_STATUS.INACTIVE && <ProjectPausedState project={project} />}