Files
supabase/apps/studio/data/storage/bucket-prefix-delete-mutation.ts
Joshen Lim 1baaded0bb Consolidate execute-sql-query into execute-sql-mutation (#46944)
## Context

Just some clean up as I was going through stuff
- `useExecuteSqlQuery` is deprecated and not used at all
- As such `execute-sql-query` is technically irrelevant, the more
relevant file is `execute-sql-mutation`
- Hence opting to consolidate `execute-sql-query` into
`execute-sql-mutation`
- Also removing `ExecuteSqlError` since its just re-exporting the
`ResponseError` type

There's a lot of file changes but its essentially just updating the
importing statements across the files
2026-06-16 00:07:16 +08:00

37 lines
1.3 KiB
TypeScript

import { getDeleteBucketPrefixSQL } from '@supabase/pg-meta'
import { executeSql } from '@/data/sql/execute-sql-mutation'
/**
* [Joshen] JFYI this is solely being used in storage-explorer.tsx and hence doesn't have a useMutation hook
* It's solely supposed to aid users to self-remediate a known issue with orphan prefixes so the condition to
* clean the prefix from the storage.prefixes is intentionally strict here (e.g only level 1)
*
* We can make this a bit more loose if needed, but ideal case is that this issue is addressed at the storage level
*/
type DeleteBucketPrefixParams = {
projectRef?: string
connectionString?: string
bucketId?: string
prefix?: string
}
export const deleteBucketPrefix = async (
{ projectRef, connectionString, bucketId, prefix }: DeleteBucketPrefixParams,
signal?: AbortSignal
) => {
if (!projectRef) throw new Error('projectRef is required')
if (!connectionString) throw new Error('connectionString is required')
if (!bucketId) throw new Error('bucketId is required')
if (!prefix) throw new Error('prefix is required')
const sql = getDeleteBucketPrefixSQL({ bucketId, prefix })
const { result } = await executeSql(
{ projectRef, connectionString, sql, queryKey: ['delete-bucket-prefix'] },
signal
)
return result
}