From 8adf98ed9640d74976d3657bb35ca274936e515a Mon Sep 17 00:00:00 2001 From: Terry Sutton Date: Wed, 8 May 2024 15:02:55 -0230 Subject: [PATCH] Pass exposed schemas to lint query (#25784) * Pass exposed schemas to lint query * Type cleanup --- apps/studio/data/lint/lint-query.ts | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/apps/studio/data/lint/lint-query.ts b/apps/studio/data/lint/lint-query.ts index 5cc1dfc1697..58bbdf31c72 100644 --- a/apps/studio/data/lint/lint-query.ts +++ b/apps/studio/data/lint/lint-query.ts @@ -2,9 +2,9 @@ import { UseQueryOptions, useQuery } from '@tanstack/react-query' import { executeSql } from '../sql/execute-sql-query' import { lintKeys } from './keys' +import { useProjectPostgrestConfigQuery } from 'data/config/project-postgrest-config-query' export const LINT_SQL = /* SQL */ `set local search_path = ''; - ( with foreign_keys as ( select @@ -817,17 +817,20 @@ export type Lint = { export type ProjectLintsVariables = { projectRef?: string connectionString?: string + exposedSchemas?: string } const getProjectLints = async ( - { projectRef, connectionString }: ProjectLintsVariables, + { projectRef, connectionString, exposedSchemas }: ProjectLintsVariables, signal?: AbortSignal ) => { + const exposedSchemasPrepend = `set local pgrst.db_schemas='${exposedSchemas}';` + const { result } = await executeSql( { projectRef, connectionString, - sql: LINT_SQL, + sql: exposedSchemasPrepend?.concat(LINT_SQL), queryKey: lintKeys.lint(projectRef), }, signal @@ -840,14 +843,20 @@ export type ProjectLintsData = Lint[] export type ProjectLintsError = unknown export const useProjectLintsQuery = ( - { projectRef, connectionString }: ProjectLintsVariables, - { enabled, ...options }: UseQueryOptions = {} -) => - useQuery( + { projectRef, connectionString }: Omit, + { enabled = true, ...options }: UseQueryOptions = {} +) => { + const { data, isSuccess } = useProjectPostgrestConfigQuery({ projectRef }) + + const exposedSchemas = data?.db_schema + + return useQuery( lintKeys.lint(projectRef), - ({ signal }) => getProjectLints({ projectRef, connectionString }, signal), + ({ signal }) => + getProjectLints({ projectRef, connectionString, exposedSchemas: exposedSchemas! }, signal), { - enabled: enabled && typeof projectRef !== 'undefined', + enabled: enabled && isSuccess && typeof projectRef !== 'undefined', ...options, } ) +}