mirror of
https://github.com/supabase/supabase.git
synced 2026-05-30 01:12:22 +08:00
* Add settings for queues: toggle expose through postgrest + permissions via table privileges * Ensure appropriate grants are granted when toggling, and revoked when disabling * Update to use queues_public schema * Update queue schema to pgmq_public and add/remove from data api when enabling/disabling * Fix query for retrieving toggle state * Add schema invalidation * Remove hard code * Use QueuesSettings from Queues folder, remove from NewQueues * Update SQL for toggling exposure + support RLS enabling * Support toggling RLS for a queue * Update admonition copy in queues for enabling/disable postgrest exposure * Add custom RLS policy for queue * Minor style fixes * Fix * Remove hard code * Update RLS to add message regarding relevancy only if exposure to PostgREST is enabled * Update message in exposing queues to postgREST * Address feedback * Address feedback * Don't revoke postgres role stuff * Remove hard code * Update copy * Update * Address Oli's feedback, ensure that queues ALL have RLS enabled prior to allowing exposure to PostgREST * Address remaining feedback * Remove hardcode * Update * Address feedback
60 lines
1.7 KiB
TypeScript
60 lines
1.7 KiB
TypeScript
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import { executeSql } from 'data/sql/execute-sql-query'
|
|
import type { ResponseError } from 'types'
|
|
import { databaseQueuesKeys } from './keys'
|
|
|
|
export type DatabaseQueueDeleteVariables = {
|
|
projectRef: string
|
|
connectionString?: string
|
|
queueName: string
|
|
}
|
|
|
|
export async function deleteDatabaseQueue({
|
|
projectRef,
|
|
connectionString,
|
|
queueName,
|
|
}: DatabaseQueueDeleteVariables) {
|
|
const { result } = await executeSql({
|
|
projectRef,
|
|
connectionString,
|
|
sql: `select * from pgmq.drop_queue('${queueName}');`,
|
|
queryKey: databaseQueuesKeys.delete(queueName),
|
|
})
|
|
|
|
return result
|
|
}
|
|
|
|
type DatabaseQueueDeleteData = Awaited<ReturnType<typeof deleteDatabaseQueue>>
|
|
|
|
export const useDatabaseQueueDeleteMutation = ({
|
|
onSuccess,
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseMutationOptions<DatabaseQueueDeleteData, ResponseError, DatabaseQueueDeleteVariables>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation<DatabaseQueueDeleteData, ResponseError, DatabaseQueueDeleteVariables>(
|
|
(vars) => deleteDatabaseQueue(vars),
|
|
{
|
|
async onSuccess(data, variables, context) {
|
|
const { projectRef } = variables
|
|
await queryClient.invalidateQueries(databaseQueuesKeys.list(projectRef))
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
async onError(data, variables, context) {
|
|
if (onError === undefined) {
|
|
toast.error(`Failed to delete database queue: ${data.message}`)
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
}
|
|
)
|
|
}
|