mirror of
https://github.com/supabase/supabase.git
synced 2026-05-07 17:30:25 -04:00
116faefcda
## Summary - Converts ~27 `executeSql` call sites in `apps/studio/data/**` to build SQL through `safeSql` / `ident` / `literal` / `keyword` / `joinSqlFragments` instead of raw template-string interpolation. - Tightens the `useDatabaseCronJobCreateMutation` and `useDatabaseEventTriggerCreateMutation` `sql`/`query` parameter types from `string` to `SafeSqlFragment` (callers already produce one). - Updates `getDeleteEnumeratedTypeSQL` in `packages/pg-meta` to return `SafeSqlFragment`. - Fixes a bug noticed while testing where Queues integration does not correctly handle queues with uppercase names. ## Pages to manually test - Integrations > Cron Jobs - Integrations > Queues - Database > Triggers > Event Triggers - Database > Indexes - Reports > Query Performance - Storage <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Queue lookups now correctly handle case-insensitive queue names. * Queue table references are now properly managed and consistently applied throughout the queue management interface. * Improved queue name display normalization in the user interface. * **Chores** * Enhanced SQL query safety across the database layer through parameterized query construction and safer templating approaches. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
import { safeSql } from '@supabase/pg-meta/src/pg-format'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { databaseKeys } from './keys'
|
|
import { executeSql } from '@/data/sql/execute-sql-query'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { PROJECT_STATUS } from '@/lib/constants'
|
|
import type { ResponseError, UseCustomQueryOptions } from '@/types'
|
|
|
|
export type SupamonitorEnabledVariables = {
|
|
projectRef?: string
|
|
connectionString?: string | null
|
|
}
|
|
|
|
export async function getSupamonitorEnabled({
|
|
projectRef,
|
|
connectionString,
|
|
}: SupamonitorEnabledVariables) {
|
|
const { result } = await executeSql<{ libraries: string }[]>({
|
|
projectRef,
|
|
connectionString,
|
|
sql: safeSql`SELECT current_setting('shared_preload_libraries', true) AS libraries`,
|
|
})
|
|
|
|
const libraries = result[0]?.libraries ?? ''
|
|
return libraries.split(',').some((lib) => lib.trim() === 'supamonitor')
|
|
}
|
|
|
|
export type SupamonitorEnabledData = Awaited<ReturnType<typeof getSupamonitorEnabled>>
|
|
export type SupamonitorEnabledError = ResponseError
|
|
|
|
export const useSupamonitorEnabledQuery = <TData = SupamonitorEnabledData>(
|
|
{ projectRef, connectionString }: SupamonitorEnabledVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<SupamonitorEnabledData, SupamonitorEnabledError, TData> = {}
|
|
) => {
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const isActive = project?.status === PROJECT_STATUS.ACTIVE_HEALTHY
|
|
|
|
return useQuery<SupamonitorEnabledData, SupamonitorEnabledError, TData>({
|
|
queryKey: databaseKeys.supamonitorEnabled(projectRef),
|
|
queryFn: () => getSupamonitorEnabled({ projectRef, connectionString }),
|
|
enabled: enabled && typeof projectRef !== 'undefined' && isActive,
|
|
...options,
|
|
})
|
|
}
|