mirror of
https://github.com/supabase/supabase.git
synced 2026-10-12 04:45:08 +03:00
* Fix childProps in Admonition so that they're added as a prop to the main div. * Replace the admonition with Alert in Wrapper tab page to add a gap between childs. * Add s3 vectors fdw. * Minor fix to FormSection. * Update the fdw mutations to support passing in options. * Refactor the vector flow to create fdws. * Revert cron description change. * If the bucket can't be created, don't create a fdw. * Update/delete the fdw when deleting a table or a bucket. * Minor fixes. * Clean up the delete modal. * Handle edge cases when missing a wrapper. * Remove the admonition in the create bucket modal. * Fix the loading state when creating a bucket. * Fix the createWrapper sheet to work with s3 vectors. * Fix undefined wrapperMeta issue. * Create the schema when installing a wrapper. * Tiny cleanup. * Clean up unneeded useState. Create a wrapper only if the all conditions are met. * Fix all comments. * Add s3 vectors for docs. * Add a link and fix the file name for S3 Vectors in docs. * Hide the table editor button if the wrapper instance is missing. * Small fixes.
74 lines
2.3 KiB
TypeScript
74 lines
2.3 KiB
TypeScript
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import { entityTypeKeys } from 'data/entity-types/keys'
|
|
import { foreignTableKeys } from 'data/foreign-tables/keys'
|
|
import { executeSql } from 'data/sql/execute-sql-query'
|
|
import { wrapWithTransaction } from 'data/sql/utils/transaction'
|
|
import type { ResponseError, UseCustomMutationOptions } from 'types'
|
|
import { fdwKeys } from './keys'
|
|
|
|
export type FDWDropForeignTableVariables = {
|
|
projectRef?: string
|
|
connectionString?: string | null
|
|
schemaName: string
|
|
tableName: string
|
|
}
|
|
|
|
export function getDropForeignTableSql({
|
|
schemaName,
|
|
tableName,
|
|
}: Omit<FDWDropForeignTableVariables, 'projectRef' | 'connectionString'>) {
|
|
const sql = /* SQL */ `
|
|
drop foreign table if exists "${schemaName}"."${tableName}";
|
|
`
|
|
|
|
return sql
|
|
}
|
|
|
|
export async function dropForeignTable({
|
|
projectRef,
|
|
connectionString,
|
|
...rest
|
|
}: FDWDropForeignTableVariables) {
|
|
const sql = wrapWithTransaction(getDropForeignTableSql(rest))
|
|
const { result } = await executeSql({ projectRef, connectionString, sql })
|
|
return result
|
|
}
|
|
|
|
type DropForeignTableData = Awaited<ReturnType<typeof dropForeignTable>>
|
|
|
|
export const useFDWDropForeignTableMutation = ({
|
|
onSuccess,
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseCustomMutationOptions<DropForeignTableData, ResponseError, FDWDropForeignTableVariables>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation<DropForeignTableData, ResponseError, FDWDropForeignTableVariables>({
|
|
mutationFn: (vars) => dropForeignTable(vars),
|
|
async onSuccess(data, variables, context) {
|
|
const { projectRef } = variables
|
|
|
|
await Promise.all([
|
|
queryClient.invalidateQueries({ queryKey: fdwKeys.list(projectRef), refetchType: 'all' }),
|
|
queryClient.invalidateQueries({ queryKey: entityTypeKeys.list(projectRef) }),
|
|
queryClient.invalidateQueries({ queryKey: foreignTableKeys.list(projectRef) }),
|
|
])
|
|
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
async onError(data, variables, context) {
|
|
if (onError === undefined) {
|
|
toast.error(`Failed to drop foreign table for foreign data wrapper: ${data.message}`)
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
})
|
|
}
|