The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix: bucket delete wait for all files to be deleted (#40992)
Ali Waseem8ea734eaa2f4
diff --git a/apps/studio/components/interfaces/Storage/__tests__/DeleteBucketModal.test.tsx b/apps/studio/components/interfaces/Storage/__tests__/DeleteBucketModal.test.tsxindex fa0f4fe3252..22747ec2364 100644--- a/apps/studio/components/interfaces/Storage/__tests__/DeleteBucketModal.test.tsx+++ b/apps/studio/components/interfaces/Storage/__tests__/DeleteBucketModal.test.tsx@@ -90,12 +90,18 @@ describe(`DeleteBucketModal`, () => {},],})- // useBucketDeleteMutation+ // useBucketDeleteMutation - empty bucketaddAPIMock({method: `post`,path: `/platform/storage/:ref/buckets/:id/empty`,})- // useDatabasePolicyDeleteMutation+ // useBucketDeleteMutation - poll for empty bucket+ addAPIMock({+ method: `post`,+ path: `/platform/storage/:ref/buckets/:id/objects/list`,+ response: [], // Return empty array to indicate bucket is empty+ })+ // useBucketDeleteMutation - delete bucketaddAPIMock({method: `delete`,path: `/platform/storage/:ref/buckets/:id`,diff --git a/apps/studio/data/storage/bucket-delete-mutation.ts b/apps/studio/data/storage/bucket-delete-mutation.tsindex 3e69ef78a00..eda1cde9b56 100644--- a/apps/studio/data/storage/bucket-delete-mutation.ts+++ b/apps/studio/data/storage/bucket-delete-mutation.ts@@ -4,6 +4,7 @@ import { toast } from 'sonner'import { del, handleError, post } from 'data/fetchers'import type { ResponseError, UseCustomMutationOptions } from 'types'import { storageKeys } from './keys'+import { pollUntilBucketEmpty } from './bucket-util'type BucketDeleteVariables = {projectRef: string@@ -19,6 +20,8 @@ async function deleteBucket({ projectRef, id }: BucketDeleteVariables) {})if (emptyBucketError) handleError(emptyBucketError)+ await pollUntilBucketEmpty({ projectRef, bucketId: id })+const { data, error: deleteBucketError } = await del('/platform/storage/{ref}/buckets/{id}', {params: { path: { ref: projectRef, id } },} as any)diff --git a/apps/studio/data/storage/bucket-util.ts b/apps/studio/data/storage/bucket-util.tsnew file mode 100644index 00000000000..fb7f20efefb--- /dev/null+++ b/apps/studio/data/storage/bucket-util.ts@@ -0,0 +1,35 @@+import { listBucketObjects } from './bucket-objects-list-mutation'++const DEFAULT_INTERVAL_MS = 3000+const DEFAULT_MAX_ATTEMPTS = 60++export async function pollUntilBucketEmpty({+ projectRef,+ bucketId,+ intervalMs = DEFAULT_INTERVAL_MS,+ maxAttempts = DEFAULT_MAX_ATTEMPTS,+}: {+ projectRef: string+ bucketId: string+ intervalMs?: number+ maxAttempts?: number+}): Promise<void> {+ for (let attempt = 0; attempt < maxAttempts; attempt++) {+ const objects = await listBucketObjects({+ projectRef,+ bucketId,+ path: '',+ options: {+ limit: 10,+ },+ })++ if (objects.length === 0) {+ return+ }++ await new Promise((resolve) => setTimeout(resolve, intervalMs))+ }++ throw new Error('Failed to empty bucket. Please try again in a few minutes.')+}