Skip to content

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

feat: allow generic schema migration with rollback

Qiao Han381404007a69
diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationActions.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationActions.tsx
index 43369381a80..fa834094654 100644
--- a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationActions.tsx
+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationActions.tsx
@@ -6,13 +6,9 @@ import { Button, IconExternalLink } from 'ui'
import { Project } from 'types'
-// [Joshen TODO] Remove all things about "ownerReassignStatus" after 5th November
-// double check with Qiao before we remove them.
-
interface NotificationActionsProps {
project: Project
changelogLink?: string
- ownerReassignStatus?: any
availableActions: Action[]
onSelectRestartProject: () => void
onSelectApplyMigration: () => void
@@ -23,7 +19,6 @@ interface NotificationActionsProps {
const NotificationActions = ({
project,
changelogLink,
- ownerReassignStatus,
availableActions,
onSelectRestartProject,
onSelectApplyMigration,
@@ -55,27 +50,21 @@ const NotificationActions = ({
case ActionType.MigratePostgresSchema:
if (action.reason === ActionReason.Finalize) {
return (
- ownerReassignStatus?.desired !== 'migrated' && (
- <Button type="default" onClick={onSelectFinalizeMigration}>
- Finalize
- </Button>
- )
+ <Button type="default" onClick={onSelectFinalizeMigration}>
+ Finalize
+ </Button>
)
} else if (action.reason === ActionReason.Rollback) {
return (
- ownerReassignStatus?.desired === 'temp_role' && (
- <Button type="default" onClick={onSelectRollbackMigration}>
- Rollback
- </Button>
- )
+ <Button type="default" onClick={onSelectRollbackMigration}>
+ Rollback
+ </Button>
)
} else {
return (
- ownerReassignStatus?.desired === 'unmigrated' && (
- <Button type="default" onClick={onSelectApplyMigration}>
- Apply now
- </Button>
- )
+ <Button type="default" onClick={onSelectApplyMigration}>
+ Apply now
+ </Button>
)
}
}
diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationRow.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationRow.tsx
index 54d19628a36..35324b9ba25 100644
--- a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationRow.tsx
+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationRow.tsx
@@ -39,18 +39,6 @@ const NotificationRow = ({
const changelogLink = (notification.data as any).changelog_link
const availableActions = notification.meta?.actions_available ?? []
- // [Joshen TODO] This should be removed after the env of Feb when the migration notifications
- // have been removed, double check with Qiao before removing.
- // Relevant PR: https://github.com/supabase/supabase/pull/9229
- const { data: ownerReassignStatus } = useQuery(
- ['projects', project?.ref, 'owner-reassign'],
- ({ signal }) => get(`${API_URL}/database/${project?.ref}/owner-reassign`, { signal }),
- {
- enabled:
- (notification.data as any).upgrade_type === 'schema-migration' && project !== undefined,
- }
- )
-
const dismissNotification = async (notificationId: string) => {
if (!notificationId) return
setDismissing(true)
@@ -80,8 +68,8 @@ const NotificationRow = ({
<div className="flex-grow mr-8 flex flex-col gap-4">
<div className="w-full flex justify-between">
<div className="w-9/10 space-y-2">
- {formatNotificationText(project, notification, ownerReassignStatus)}
- {formatNotificationCTAText(availableActions, ownerReassignStatus)}
+ {formatNotificationText(project, notification)}
+ {formatNotificationCTAText(availableActions)}
<p className="text-scale-1100 text-sm !mt-2">{insertedAt}</p>
</div>
<div className="w-1/10 flex justify-end">
@@ -124,7 +112,6 @@ const NotificationRow = ({
<NotificationActions
project={project}
changelogLink={changelogLink}
- ownerReassignStatus={ownerReassignStatus}
availableActions={availableActions}
onSelectRestartProject={() => onSelectRestartProject(project, notification)}
onSelectApplyMigration={() => onSelectApplyMigration(project, notification)}
diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationRows.utils.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationRows.utils.tsx
index bfc0b5a8978..dc7313cfe82 100644
--- a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationRows.utils.tsx
+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationRows.utils.tsx
@@ -17,7 +17,6 @@ import Link from 'next/link'
export const formatNotificationText = (
project: Project,
notification: Notification,
- ownerReassignStatus?: any
) => {
const projectName = project.name
@@ -89,28 +88,12 @@ export const formatNotificationText = (
)
} else if (upgrade_type === 'schema-migration') {
const { version_to } = additional
- if (ownerReassignStatus?.desired === 'unmigrated') {
- return (
- <p className="text-sm">
- The schema migration "{version_to}" will be applied for project "{projectName}" within a
- few days. You may opt to apply the changes now, or it'll be done so automatically.
- </p>
- )
- } else if (ownerReassignStatus?.desired === 'temp_role') {
- return (
- <p className="text-sm">
- The schema migration "{version_to}" will be finalized for project "{projectName}" within
- a few days. You may opt to finalize the changes now, or it'll be done so automatically.
- </p>
- )
- } else {
- return (
- <p className="text-sm">
- The schema migration "{version_to}" has been successfully applied for project "
- {projectName}".
- </p>
- )
- }
+ return (
+ <p className="text-sm">
+ The schema migration "{version_to}" has been successfully applied for project "
+ {projectName}".
+ </p>
+ )
}
} else if (notification.data.name === NotificationName.ProjectUpdateCompleted) {
const { upgrades } = notification.data
@@ -178,7 +161,6 @@ export const formatNotificationText = (
export const formatNotificationCTAText = (
availableActions: Action[],
- ownerReassignStatus?: any
) => {
const [action] = availableActions
if (!action) return <p className="text-sm"></p>
@@ -192,43 +174,13 @@ export const formatNotificationCTAText = (
return <p className="text-sm">Restart your connection pooler to get the latest updates.</p>
case ActionType.MigratePostgresSchema:
if (action.deadline) {
- if (ownerReassignStatus?.desired === 'migrated') {
- return (
- <p className="text-sm space-x-1">
- This patch was applied on{' '}
- {dayjs(new Date(ownerReassignStatus.migrated_at ?? action.deadline)).format(
- 'DD MMM YYYY, HH:mma'
- )}
- </p>
- )
- } else if (ownerReassignStatus?.desired === 'temp_role') {
- if (action.reason === ActionReason.Finalize) {
- return (
- <p className="text-sm space-x-1">
- This patch will be automatically applied after{' '}
- {dayjs(new Date(action.deadline)).format('DD MMM YYYY, HH:mma')}
- </p>
- )
- } else {
- return (
- <p className="text-sm space-x-1">
- This patch was applied on{' '}
- {dayjs(new Date(ownerReassignStatus.modified_at)).format('DD MMM YYYY, HH:mma')}
- </p>
- )
- }
- } else {
- return (
- <p className="text-sm space-x-1">
- This patch will be automatically applied after{' '}
- {dayjs(new Date(action.deadline)).format('DD MMM YYYY, HH:mma')}
- </p>
- )
- }
- } else {
- return ''
+ return (
+ <p className="text-sm space-x-1">
+ This patch will be automatically applied after{' '}
+ {dayjs(new Date(action.deadline)).format('DD MMM YYYY, HH:mma')}
+ </p>
+ )
}
-
default:
return ''
}
diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/index.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/index.tsx
index d11b4f510a2..9f28a239a9c 100644
--- a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/index.tsx
+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/index.tsx
@@ -3,6 +3,7 @@ import {
ActionType,
Notification,
NotificationStatus,
+ PostgresqlUpgradeData,
} from '@supabase/shared-types/out/notifications'
import { useQueryClient } from '@tanstack/react-query'
import dayjs from 'dayjs'
@@ -98,16 +99,12 @@ const NotificationsPopover = ({ alt = false }: NotificationsPopoverProps) => {
setTargetNotification(undefined)
}
- // [Joshen/Qiao] These are all very specific to the upcoming security patch
- // https://github.com/supabase/supabase/discussions/9314
- // We probably need to revisit this again when we're planning to push out the next wave of
- // notifications. Ideally, we should allow these to be more flexible and configurable
- // Perhaps the URLs could come from the notification themselves if the actions
- // require an external API call, then we just need one method instead of individual ones like this
-
const onConfirmProjectApplyMigration = async () => {
if (!projectToApplyMigration) return
- const res = await post(`${API_URL}/database/${projectToApplyMigration.ref}/owner-reassign`, {})
+ const data = targetNotification?.data as PostgresqlUpgradeData
+ const { resource } = data.additional as any
+ if (!resource) return
+ const res = await post(`${API_URL}/database/${projectToApplyMigration.ref}/${resource}`, {})
if (!res.error) {
const project = await getProjectDetail({ ref: projectToApplyMigration.ref })
if (project) {
@@ -130,8 +127,11 @@ const NotificationsPopover = ({ alt = false }: NotificationsPopoverProps) => {
const onConfirmProjectRollbackMigration = async () => {
if (!projectToRollbackMigration) return
+ const data = targetNotification?.data as PostgresqlUpgradeData
+ const { resource } = data.additional as any
+ if (!resource) return
const res = await delete_(
- `${API_URL}/database/${projectToRollbackMigration.ref}/owner-reassign`,
+ `${API_URL}/database/${projectToRollbackMigration.ref}/${resource}`,
{}
)
if (!res.error) {
@@ -156,10 +156,10 @@ const NotificationsPopover = ({ alt = false }: NotificationsPopoverProps) => {
const onConfirmProjectFinalizeMigration = async () => {
if (!projectToFinalizeMigration) return
- const res = await patch(
- `${API_URL}/database/${projectToFinalizeMigration.ref}/owner-reassign`,
- {}
- )
+ const data = targetNotification?.data as PostgresqlUpgradeData
+ const { resource } = data.additional as any
+ if (!resource) return
+ const res = await patch(`${API_URL}/database/${projectToFinalizeMigration.ref}/${resource}`, {})
if (!res.error) {
const project = await getProjectDetail({ ref: projectToFinalizeMigration.ref })
if (project) {