fix: Remove aggregates, procedures and window functions from schema cache and OpenAPI output
Aggregates and Window functions can't be called as RPCs in a useful way. Procedures are not supported right now, but might be added later. Resolves #2101 Signed-off-by: Wolfgang Walther <walther@technowledgy.de>
This commit is contained in:
committed by
Wolfgang Walther
parent
ded8981368
commit
bd62008e1c
@@ -483,7 +483,7 @@ handleOpenApi headersOnly tSchema (RequestContext conf@AppConfig{..} dbStructure
|
||||
OAFollowPriv ->
|
||||
OpenAPI.encode conf dbStructure
|
||||
<$> SQL.statement tSchema (DbStructure.accessibleTables ctxPgVersion configDbPreparedStatements)
|
||||
<*> SQL.statement tSchema (DbStructure.accessibleProcs configDbPreparedStatements)
|
||||
<*> SQL.statement tSchema (DbStructure.accessibleProcs ctxPgVersion configDbPreparedStatements)
|
||||
<*> SQL.statement tSchema (DbStructure.schemaDescription configDbPreparedStatements)
|
||||
OAIgnorePriv ->
|
||||
OpenAPI.encode conf dbStructure
|
||||
|
||||
@@ -42,7 +42,8 @@ import Data.Text (split)
|
||||
import Text.InterpolatedString.Perl6 (q)
|
||||
|
||||
import PostgREST.Config.Database (pgVersionStatement)
|
||||
import PostgREST.Config.PgVersion (PgVersion, pgVersion100)
|
||||
import PostgREST.Config.PgVersion (PgVersion, pgVersion100,
|
||||
pgVersion110)
|
||||
import PostgREST.DbStructure.Identifiers (QualifiedIdentifier (..),
|
||||
Schema, TableName)
|
||||
import PostgREST.DbStructure.Proc (PgType (..),
|
||||
@@ -93,7 +94,7 @@ queryDbStructure schemas extraSearchPath prepared = do
|
||||
srcCols <- SQL.statement (schemas, extraSearchPath) $ pfkSourceColumns cols prepared
|
||||
m2oRels <- SQL.statement mempty $ allM2ORels tabs cols prepared
|
||||
keys <- SQL.statement mempty $ allPrimaryKeys tabs prepared
|
||||
procs <- SQL.statement schemas $ allProcs prepared
|
||||
procs <- SQL.statement schemas $ allProcs pgVer prepared
|
||||
|
||||
let rels = addO2MRels . addM2MRels $ addViewM2ORels srcCols m2oRels
|
||||
keys' = addViewPrimaryKeys srcCols keys
|
||||
@@ -228,18 +229,18 @@ decodeProcs =
|
||||
| v == 's' = Stable
|
||||
| otherwise = Volatile -- only 'v' can happen here
|
||||
|
||||
allProcs :: Bool -> SQL.Statement [Schema] ProcsMap
|
||||
allProcs = SQL.Statement sql (arrayParam HE.text) decodeProcs
|
||||
allProcs :: PgVersion -> Bool -> SQL.Statement [Schema] ProcsMap
|
||||
allProcs pgVer = SQL.Statement sql (arrayParam HE.text) decodeProcs
|
||||
where
|
||||
sql = procsSqlQuery <> " AND pn.nspname = ANY($1)"
|
||||
sql = procsSqlQuery pgVer <> " AND pn.nspname = ANY($1)"
|
||||
|
||||
accessibleProcs :: Bool -> SQL.Statement Schema ProcsMap
|
||||
accessibleProcs = SQL.Statement sql (param HE.text) decodeProcs
|
||||
accessibleProcs :: PgVersion -> Bool -> SQL.Statement Schema ProcsMap
|
||||
accessibleProcs pgVer = SQL.Statement sql (param HE.text) decodeProcs
|
||||
where
|
||||
sql = procsSqlQuery <> " AND pn.nspname = $1 AND has_function_privilege(p.oid, 'execute')"
|
||||
sql = procsSqlQuery pgVer <> " AND pn.nspname = $1 AND has_function_privilege(p.oid, 'execute')"
|
||||
|
||||
procsSqlQuery :: SqlQuery
|
||||
procsSqlQuery = [q|
|
||||
procsSqlQuery :: PgVersion -> SqlQuery
|
||||
procsSqlQuery pgVer = [q|
|
||||
-- Recursively get the base types of domains
|
||||
WITH
|
||||
base_types AS (
|
||||
@@ -303,7 +304,7 @@ procsSqlQuery = [q|
|
||||
LEFT JOIN pg_class comp ON comp.oid = t.typrelid
|
||||
LEFT JOIN pg_catalog.pg_description as d ON d.objoid = p.oid
|
||||
WHERE t.oid <> 'pg_catalog.trigger'::regtype
|
||||
|]
|
||||
|] <> (if pgVer >= pgVersion110 then "AND prokind = 'f'" else "AND NOT (proisagg OR proiswindow)")
|
||||
|
||||
schemaDescription :: Bool -> SQL.Statement Schema (Maybe Text)
|
||||
schemaDescription =
|
||||
|
||||
Reference in New Issue
Block a user