The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
chore: reinstate backup download button (#18070)
angelico19746b124529
diff --git a/studio/components/interfaces/Database/Backups/BackupItem.tsx b/studio/components/interfaces/Database/Backups/BackupItem.tsxindex d049e439edf..6023c3f7305 100644--- a/studio/components/interfaces/Database/Backups/BackupItem.tsx+++ b/studio/components/interfaces/Database/Backups/BackupItem.tsx@@ -1,22 +1,37 @@import { PermissionAction } from '@supabase/shared-types/out/constants'import dayjs from 'dayjs'-import { Badge, Button } from 'ui'+import { Badge, Button, IconDownload } from 'ui'+import { useBackupDownloadMutation } from 'data/database/backup-download-mutation'import { DatabaseBackup } from 'data/database/backups-query'import { useCheckPermissions } from 'hooks'interface BackupItemProps {index: number+ projectRef: stringbackup: DatabaseBackuponSelectBackup: () => void}-const BackupItem = ({ index, backup, onSelectBackup }: BackupItemProps) => {+const BackupItem = ({ index, backup, projectRef, onSelectBackup }: BackupItemProps) => {const canTriggerScheduledBackups = useCheckPermissions(PermissionAction.INFRA_EXECUTE,'queue_job.restore.prepare')+ 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 generateSideButtons = (backup: any) => {if (backup.status === 'COMPLETED')return (@@ -24,6 +39,17 @@ const BackupItem = ({ index, backup, onSelectBackup }: BackupItemProps) => {<Button type="default" disabled={!canTriggerScheduledBackups} onClick={onSelectBackup}>Restore</Button>+ {!backup.isPhysicalBackup && (+ <Button+ type="default"+ disabled={!canTriggerScheduledBackups || isDownloading}+ onClick={() => downloadBackup({ ref: projectRef, backup })}+ loading={isDownloading}+ icon={<IconDownload />}+ >+ Download+ </Button>+ )}</div>)return <Badge color="yellow">Backup In Progress...</Badge>diff --git a/studio/components/interfaces/Database/Backups/BackupsList.tsx b/studio/components/interfaces/Database/Backups/BackupsList.tsxindex 337565eef36..1b2be25cd1b 100644--- a/studio/components/interfaces/Database/Backups/BackupsList.tsx+++ b/studio/components/interfaces/Database/Backups/BackupsList.tsx@@ -92,6 +92,7 @@ const BackupsList = () => {<BackupItemkey={x.id}backup={x}+ projectRef={projectRef}index={i}onSelectBackup={() => setSelectedBackup(x)}/>diff --git a/studio/data/database/backup-download-mutation.ts b/studio/data/database/backup-download-mutation.tsnew file mode 100644index 00000000000..72f33167a3e--- /dev/null+++ b/studio/data/database/backup-download-mutation.ts@@ -0,0 +1,56 @@+import { useMutation, UseMutationOptions } from '@tanstack/react-query'+import { toast } from 'react-hot-toast'++import { post } from 'data/fetchers'+import { ResponseError } from 'types'+import { Backup } from './backup-restore-mutation'++export type BackupDownloadVariables = {+ ref: string+ backup: Backup+}++export async function downloadBackup({ ref, backup }: BackupDownloadVariables) {+ const { data, error } = await post('/platform/database/{ref}/backups/download', {+ params: { path: { ref } },+ body: {+ id: backup.id, // this is the only one needed actually+ inserted_at: backup.inserted_at,+ project_id: backup.project_id,+ data: {},+ s3_bucket: 'deprecated',+ s3_path: 'deprecated',+ status: 'deprecated'+ },+ })+ if (error) throw error+ return data+}++type BackupDownloadData = Awaited<ReturnType<typeof downloadBackup>>++export const useBackupDownloadMutation = ({+ onSuccess,+ onError,+ ...options+}: Omit<+ UseMutationOptions<BackupDownloadData, ResponseError, BackupDownloadVariables>,+ 'mutationFn'+> = {}) => {+ return useMutation<BackupDownloadData, ResponseError, BackupDownloadVariables>(+ (vars) => downloadBackup(vars),+ {+ async onSuccess(data, variables, context) {+ await onSuccess?.(data, variables, context)+ },+ async onError(data, variables, context) {+ if (onError === undefined) {+ toast.error(`Failed to download backup: ${data.message}`)+ } else {+ onError(data, variables, context)+ }+ },+ ...options,+ }+ )+}